-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from tronghieuvuong/tvuong/githubAPI
Import Github API to trigger workflow and fetch issues
- Loading branch information
Showing
16 changed files
with
1,272 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
ZENHUB_APIKEY | ||
ZENHUB_APIKEY | ||
GITHUB_TOKEN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
{ | ||
"tabWidth": 2, | ||
"semi": false, | ||
"singleQuote": true | ||
} | ||
"useTabs": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { getOctokit } from '~/githubClient' | ||
|
||
async function getIssue (owner: string, repo: string, teamName: string) { | ||
const issues = await getOctokit().request('GET /repos/{owner}/{repo}/issues', { | ||
owner, | ||
repo, | ||
labels: teamName | ||
}) | ||
return issues.data[0] | ||
} | ||
|
||
export default getIssue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import getIssue from './getIssues' | ||
import { getOctokit } from '~/githubClient' | ||
async function getWorkflows (owner: string, repo: string, runID: number) { | ||
const result = await getOctokit().request( | ||
'GET /repos/{owner}/{repo}/actions/runs/{runID}', | ||
{ | ||
owner, | ||
repo, | ||
runID | ||
} | ||
) | ||
|
||
return result | ||
} | ||
|
||
async function waitForSuccessStatus ( | ||
owner: string, | ||
repo: string, | ||
runID: number, | ||
teamName: string | ||
) { | ||
let attempts = 0 | ||
const maxAttempts: number = 20 | ||
const delay: number = 10000 | ||
while (attempts < maxAttempts) { | ||
console.log('hello') | ||
const res = await getWorkflows(owner, repo, runID) | ||
const status = res.data.status | ||
console.log('status' + status) | ||
if (status === 'completed') { | ||
const issues = await getIssue(owner, repo, teamName) | ||
return issues | ||
} | ||
|
||
// Wait for a specified delay before checking again | ||
await new Promise(resolve => setTimeout(resolve, delay)) | ||
|
||
attempts++ | ||
} | ||
|
||
throw new Error( | ||
"Timeout: The status did not become 'success' within the specified number of attempts." | ||
) | ||
} | ||
|
||
export default waitForSuccessStatus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { getOctokit } from '~/githubClient' | ||
|
||
async function runWorkflow (owner: string, repo: string, runID: number) { | ||
return await getOctokit().request( | ||
'POST /repos/{owner}/{repo}/actions/runs/{runID}/rerun', | ||
{ | ||
owner, | ||
repo, | ||
runID | ||
} | ||
) | ||
} | ||
|
||
export default runWorkflow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ enum BoardName { | |
NAMETEAMSPACE = 'names-team-board', | ||
} | ||
|
||
export default BoardName | ||
export default BoardName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
enum runJob { | ||
ENTITIES = 7066220176, | ||
} | ||
|
||
export default runJob |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
enum workflowRun { | ||
OWNER = 'bcgov', | ||
REPO = 'metrics-report', | ||
} | ||
|
||
export default workflowRun |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Octokit } from 'octokit' | ||
export function getOctokit () { | ||
const config = useRuntimeConfig() | ||
const octokit = new Octokit({ | ||
auth: config.public.githubToken | ||
}) | ||
return octokit | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.