Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import Github API to trigger workflow and fetch issues #41

Merged
merged 5 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where are you pulling GITHUB_TOKEN from? If you want this variable to be in gcbrun, you will need to add it here:


If you also want it to be loaded in the builds from 1password, you will need to add it here https://github.com/bcgov/sbc-producthub/blob/main/apps/application-status/vaults.env probably something like GITHUB_TOKEN ="op://API/$APP_ENV/github/GITHUB_TOKEN"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I did not have the permission to add the key on GCP or 1password yet, therefore, gcbrun build is currently failing to display, and the same for dev build

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sent you direct message about the key value, as I don't know which value you are using

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
}
15 changes: 15 additions & 0 deletions apps/application-status/composables/getIssues.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
tronghieuvuong marked this conversation as resolved.
Show resolved Hide resolved
}
})
return issues.data[0]
}

export default getIssue
49 changes: 49 additions & 0 deletions apps/application-status/composables/getWorkFlows.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
}
)

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
17 changes: 17 additions & 0 deletions apps/application-status/composables/runWorkFlow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
}
)
}

export default runWorkflow
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
Loading