Skip to content

Commit

Permalink
Merge pull request #41 from tronghieuvuong/tvuong/githubAPI
Browse files Browse the repository at this point in the history
Import Github API to trigger workflow and fetch issues
  • Loading branch information
tronghieuvuong authored Dec 4, 2023
2 parents d6afc02 + 15f36c5 commit 0cd1d36
Show file tree
Hide file tree
Showing 16 changed files with 1,272 additions and 137 deletions.
3 changes: 2 additions & 1 deletion apps/application-status/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ZENHUB_APIKEY
ZENHUB_APIKEY
GITHUB_TOKEN
5 changes: 2 additions & 3 deletions apps/application-status/.prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"tabWidth": 2,
"semi": false,
"singleQuote": true
}
"useTabs": false
}
12 changes: 12 additions & 0 deletions apps/application-status/composables/getIssues.ts
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
46 changes: 46 additions & 0 deletions apps/application-status/composables/getWorkFlows.ts
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
14 changes: 14 additions & 0 deletions apps/application-status/composables/runWorkFlow.ts
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
1 change: 1 addition & 0 deletions apps/application-status/devops/cloudbuild-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ steps:
dir: 'apps/application-status'
env:
- 'ZENHUB_APIKEY=$_ZENHUB_APIKEY'
- 'GITHUB_TOKEN=$_GITHUB_TOKEN'

#
# Deploy to firebase channel, using the PR #
Expand Down
2 changes: 1 addition & 1 deletion apps/application-status/enums/boardName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ enum BoardName {
NAMETEAMSPACE = 'names-team-board',
}

export default BoardName
export default BoardName
5 changes: 5 additions & 0 deletions apps/application-status/enums/runJob.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enum runJob {
ENTITIES = 7066220176,
}

export default runJob
6 changes: 6 additions & 0 deletions apps/application-status/enums/workflowRun.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
enum workflowRun {
OWNER = 'bcgov',
REPO = 'metrics-report',
}

export default workflowRun
8 changes: 8 additions & 0 deletions apps/application-status/githubClient.ts
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
}
3 changes: 2 additions & 1 deletion apps/application-status/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export default defineNuxtConfig({
},
runtimeConfig: {
public: {
zenhubAPI: process.env.ZENHUB_APIKEY
zenhubAPI: process.env.ZENHUB_APIKEY,
githubToken: process.env.GITHUB_TOKEN
}
}
})
Loading

0 comments on commit 0cd1d36

Please sign in to comment.