From 0c9e435600cd25eaea96989675d80813d4d565ab Mon Sep 17 00:00:00 2001 From: partapparam Date: Mon, 20 May 2024 17:23:42 -0700 Subject: [PATCH 01/10] new-utils --- github-actions/utils/get-issue-by-label.js | 51 +++++++++++++++++++ github-actions/utils/reopen-issue.js | 35 +++++++++++++ .../utils/update-issue-project-card.js | 32 ++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 github-actions/utils/get-issue-by-label.js create mode 100644 github-actions/utils/reopen-issue.js create mode 100644 github-actions/utils/update-issue-project-card.js diff --git a/github-actions/utils/get-issue-by-label.js b/github-actions/utils/get-issue-by-label.js new file mode 100644 index 0000000000..5617cb6259 --- /dev/null +++ b/github-actions/utils/get-issue-by-label.js @@ -0,0 +1,51 @@ +/** + * Gets issue by label + * @param {String} actor - the creator of the issue + * @param {Array} labels - the labelS we want to filter by + */ +async function getIssueByLabel(actor, labels, github, context) { + try { + // TODO - How to get owner and repo dynamically + let results = await github.graphql(query, { + actor: actor, + labels: labels, + owner: "partapparam", + repository: "website", + }) + + let issue = results.repository.issues.nodes[0] + return issue + } catch (err) { + console.error(err) + throw new Error(err) + } +} + +/** + * GraphQL query template to use to execute the search. + */ +const query = ` +query ($actor: String!, $labels: [String!]!, $owner: String!, $repository: String!) { + repository (owner: $owner, name: $repository) { + issues (first: 10, filterBy: {createdBy: $actor labels: $labels}) { + nodes { + __typename + ... on Issue { + title + closed + number + url + id + projectCards { + nodes { + id + } + } + } + } + } +} +} +` + +module.exports = getIssueByLabel diff --git a/github-actions/utils/reopen-issue.js b/github-actions/utils/reopen-issue.js new file mode 100644 index 0000000000..db6340b054 --- /dev/null +++ b/github-actions/utils/reopen-issue.js @@ -0,0 +1,35 @@ +/** + * Reopen a closed issue + * @param {Number} issueId - the issue that should be reopened + */ +async function reopenIssue(issueId, github) { + try { + const response = await github.graphql(mutation, { + issueId: issueId, + }) + return response + } catch (err) { + throw new Error(err) + } +} + +/** + * GraphQL query template to use to execute the mutation. + */ +const mutation = ` +mutation ($issueId: ID!) { + reopenIssue (input: { issueId: $issueId}) { + issue { + title + state + projectCards { + nodes { + id + } + } + } + } +} +` + +module.exports = reopenIssue diff --git a/github-actions/utils/update-issue-project-card.js b/github-actions/utils/update-issue-project-card.js new file mode 100644 index 0000000000..8c64fb80ed --- /dev/null +++ b/github-actions/utils/update-issue-project-card.js @@ -0,0 +1,32 @@ +/** + * Move Issue to In Progress Column + * @param {String} issueCardId - the issue card ID + * @param {String} projectColumnId - the project column ID + */ +async function updateIssueProjectCard(issueCardId, projectColumnId, github) { + try { + await github.graphql(mutation, { + cardId: issueCardId, + columnId: projectColumnId, + }) + } catch (err) { + throw new Error(err) + } +} + +/** + * GraphQL query template to use to move project card to In Progress Column + */ +const mutation = ` +mutation ($cardId: ID! $columnId: ID!) { + moveProjectCard (input: {cardId: $cardId columnId: $columnId}) { + cardEdge { + node { + resourcePath + } + } + } +} +` + +module.exports = updateIssueProjectCard From 6a86c6ce7f0c947e509e3dc3243077ddeb68ace2 Mon Sep 17 00:00:00 2001 From: partapparam Date: Mon, 20 May 2024 18:06:55 -0700 Subject: [PATCH 02/10] added resuable workflow files --- .../add-prework-issue-comment.js | 36 +++++ .../get-activity-detail.js | 136 ++++++++++++++++++ .../get-prework-issue.js | 29 ++++ .../update-prework-issue-status.js | 30 ++++ 4 files changed, 231 insertions(+) create mode 100644 github-actions/prework-issue-reusable-workflow/add-prework-issue-comment.js create mode 100644 github-actions/prework-issue-reusable-workflow/get-activity-detail.js create mode 100644 github-actions/prework-issue-reusable-workflow/get-prework-issue.js create mode 100644 github-actions/prework-issue-reusable-workflow/update-prework-issue-status.js diff --git a/github-actions/prework-issue-reusable-workflow/add-prework-issue-comment.js b/github-actions/prework-issue-reusable-workflow/add-prework-issue-comment.js new file mode 100644 index 0000000000..1ceff2b96f --- /dev/null +++ b/github-actions/prework-issue-reusable-workflow/add-prework-issue-comment.js @@ -0,0 +1,36 @@ +// Import modules +const postComment = require("../utils/post-issue-comment") + +// Global variables +var github +var context + +/** + * @description - This function is the entry point into the javascript file, it leaves a comment on the prework issue + * @param {Object} g - github object + * @param {Object} c - context object + * @param {Number} issueNumber - issue + * @param {Object} activityDetail - details of the activity performed + */ +async function main({ g, c }, issueNumber, activityDetail) { + github = g + context = c + const comment = await makeComment(activityDetail) + if (comment !== null) { + await postComment(issueNumber, comment, github, context) + } +} + +/** + * @description - This function makes the comment + * @param {Object} activityDetail - details of the activity performed + * @returns {Promise} - Comment to be posted with the issue label event actor's name + */ + +async function makeComment(activityDetail) { + const comment = `${activityDetail.activityObject} has been ${activityDetail.action} by @${activityDetail.contributor} +` + return comment +} + +module.exports = main diff --git a/github-actions/prework-issue-reusable-workflow/get-activity-detail.js b/github-actions/prework-issue-reusable-workflow/get-activity-detail.js new file mode 100644 index 0000000000..852f67074f --- /dev/null +++ b/github-actions/prework-issue-reusable-workflow/get-activity-detail.js @@ -0,0 +1,136 @@ +// Import modules +var fs = require("fs") + +// Global variables +var github +var context + +/** + * @description - This function is the entry point into the javascript file, + * It will determine the eventName and return the proper activity detail + * @param {Object} g - github object + * @param {Object} c - context object + */ +async function main({ g, c }) { + github = g + context = c + + switch (context.eventName) { + case "issue_comment": + return await getIssueCommentEventType(context) + case "issues": + return await getIssueEventType(context) + case "pull_request": + return await getPullRequestEventType(context) + case "pull_request_review": + return await getPullRequestReviewEventType(context) + case "pull_request_review_comment": + return await getPullRequestReviewCommentEventType(context) + default: + // Handle cases where eventName doesn't match any known event type + console.log(`Unknown event name: ${context.eventName}`) + } +} + +/** + * Retrieves detailed information about an issue event based on the action performed. + * @param {*} context + * @returns - An object containing the activity detail: + * - contributor + * - action + * - object the activity was performed on (issue, issue_comment, pr, pr_comment, pr_review) + * + */ +async function getIssueEventType(context) { + const activityDetail = { + contributor: "", + action: context.payload.action, + activityObject: `Issue #${context.payload.issue.number}`, + } + if (context.payload.action == "opened") { + activityDetail.contributor = context.payload.issue.user.login + } else if (context.payload.action == "closed") { + // NOTE: context.payload.issue.assignee.login can be null if issue is not assigned and marked closed + activityDetail.contributor = context.payload.issue.assignee.login + } else { + // on unassigned event, the `issue.assignee` is null. + activityDetail.contributor = context.payload.assignee.login + } + return activityDetail +} + +/** + * Retrieves detailed information about an issue event based on the action performed. + * @param {*} context + * @returns - An object containing the activity detail: + * - contributor + * - action + * - object the activity was performed on (issue, issue_comment, pr, pr_comment, pr_review) + * + */ +async function getIssueCommentEventType(context) { + const activityDetail = { + contributor: context.payload.comment.user.login, + action: context.payload.action, + activityObject: context.payload.comment.url, + } + return activityDetail +} + +/** + * Retrieves detailed information about an issue event based on the action performed. + * @param {*} context + * @returns - An object containing the activity detail: + * - contributor + * - action + * - object the activity was performed on (issue, issue_comment, pr, pr_comment, pr_review) + * + */ +async function getPullRequestEventType(context) { + const activityDetail = { + contributor: context.payload.pull_request.user.login, + action: context.payload.action, + activityObject: `PR #${context.payload.pull_request.number}`, + } + return activityDetail +} + +/** + * Retrieves detailed information about an issue event based on the action performed. + * @param {*} context + * @returns - An object containing the activity detail: + * - contributor + * - action + * - object the activity was performed on (issue, issue_comment, pr, pr_comment, pr_review) + * + */ +async function getPullRequestReviewEventType(context) { + // also achievable by the context.sender - user who did this event + const activityDetail = { + contributor: context.payload.review.user.login, + action: context.payload.action, + activityObject: `PR #${context.payload.pull_request.number}`, + } + return activityDetail +} + +/** + * Retrieves detailed information about an issue event based on the action performed. + * @param {*} context + * @returns - An object containing the activity detail: + * - contributor + * - action + * - object the activity was performed on (issue, issue_comment, pr, pr_comment, pr_review) + * + */ +async function getPullRequestReviewCommentEventType(context) { + // also achievable by the context.sender - user who did this event + const activityDetail = { + contributor: context.payload.comment.user.login, + action: context.payload.action, + activityObject: `${context.payload.comment.url}`, + } + return activityDetail +} + +module.exports = main diff --git a/github-actions/prework-issue-reusable-workflow/get-prework-issue.js b/github-actions/prework-issue-reusable-workflow/get-prework-issue.js new file mode 100644 index 0000000000..f2f953ed41 --- /dev/null +++ b/github-actions/prework-issue-reusable-workflow/get-prework-issue.js @@ -0,0 +1,29 @@ +// Import modules +var getIssueByLabel = require("../utils/get-issue-by-label") + +// Global variables +var github +var context + +/** + * @description - This function is the entry point into the javascript file, + * it will find the prework issue + * + * @param {Object} g - github object + * @param {Object} c - context object + * @param {Object} activityDetail - person who triggered the workflow + */ +async function main({ g, c }, activityDetail) { + github = g + context = c + let labels = ["Complexity: Prework"] + const issue = await getIssueByLabel( + activityDetail.contributor, + labels, + github, + context + ) + return issue +} + +module.exports = main diff --git a/github-actions/prework-issue-reusable-workflow/update-prework-issue-status.js b/github-actions/prework-issue-reusable-workflow/update-prework-issue-status.js new file mode 100644 index 0000000000..436dd8da81 --- /dev/null +++ b/github-actions/prework-issue-reusable-workflow/update-prework-issue-status.js @@ -0,0 +1,30 @@ +// Import modules +var reopenIssue = require("../utils/reopen-issue") + +// Global variables +var github +var context + +/** + * @description - This function is the entry point into the javascript file, it will reopen the issue + * @param {Object} g - github object + * @param {Object} c - context object + * @param {Object} issue - the issue to update + */ +async function main({ g, c }, issue) { + github = g + context = c + + // TODO value is hardcoded + // Project Number =1 , for HFLA project number = 7 + const projectColumnId = "PC_lATOJyGIJc4A4juVzgEvcLk" + console.log(issue) + if (issue.closed == true) { + const result = await reopenIssue(issue.id, github) + console.log(result) + return result.reopenIssue.issue + } + return false +} + +module.exports = main From 4e6dee4dfb2711746281df3d62c15569a3ac9bab Mon Sep 17 00:00:00 2001 From: partapparam Date: Mon, 20 May 2024 18:17:51 -0700 Subject: [PATCH 03/10] update triggers --- .github/workflows/issue-trigger.yml | 10 ++- ...ework-issue-comment-reusable-workflow.yaml | 76 +++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/prework-issue-comment-reusable-workflow.yaml diff --git a/.github/workflows/issue-trigger.yml b/.github/workflows/issue-trigger.yml index f2895c5586..66c1872a35 100644 --- a/.github/workflows/issue-trigger.yml +++ b/.github/workflows/issue-trigger.yml @@ -1,7 +1,7 @@ name: Issue Trigger on: issues: - types: [opened, transferred, assigned, labeled, unlabeled] + types: [opened, closed, transferred, assigned, unassigned, labeled, unlabeled] jobs: # Adds newly created issues onto project board in the default column 'New Issue Approval' @@ -111,3 +111,11 @@ jobs: script: | const script = require('./github-actions/trigger-issue/feature-branch-comment/hide-feature-branch-comment.js') script({g: github, c: context}) + +# Adds a comment to actor's prework issue + Add-Comment-To-Prework-Issue: + if: "${{ github.event.action == 'opened' || github.event.action == 'closed' || github.event.action == 'assigned' || github.event.action == 'unassigned'}}" + permissions: + issues: write + uses: partapparam/website/.github/workflows/prework-issue-comment-reusable-workflow.yaml@gh-pages + secrets: inherit diff --git a/.github/workflows/prework-issue-comment-reusable-workflow.yaml b/.github/workflows/prework-issue-comment-reusable-workflow.yaml new file mode 100644 index 0000000000..738d26d965 --- /dev/null +++ b/.github/workflows/prework-issue-comment-reusable-workflow.yaml @@ -0,0 +1,76 @@ +name: Find Prework Issue and Comment User Activity + +on: + workflow_call: + +jobs: + Add-Comment-To-Prework-Issue: + runs-on: ubuntu-latest + permissions: + issues: write + steps: + - uses: actions/checkout@v4 + + - name: Get activity detail + id: get-activity-detail + uses: actions/github-script@v7 + with: + script: | + const script = require('./github-actions/prework-issue-reusable-workflow/get-activity-detail.js') + const contributor = script({g: github, c: context}) + return contributor + + - name: Get prework issue + id: get-prework-issue + uses: actions/github-script@v7 + with: + script: | + const script = require('./github-actions/prework-issue-reusable-workflow/get-prework-issue.js') + const activityDetail = ${{steps.get-activity-detail.outputs.result}} + return script({g: github, c: context}, activityDetail) + + - name: Update prework issue status + id: update-prework-issue-status + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.HFLA_PROJECT_BOARD_TOKEN }} + script: | + const script = require('./github-actions/prework-issue-reusable-workflow/update-prework-issue-status.js') + const issue = ${{steps.get-prework-issue.outputs.result}} + return script({g: github, c: context}, issue) + + # Only move issue if issue was closed and is reopened + - name: Move issue + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.HFLA_PROJECT_BOARD_TOKEN }} + script: | + const projectColumnId = "PC_lATOJyGIJc4A4juVzgEvcLk" + let mutation = ` + mutation ($cardId: ID! $columnId: ID!) { + moveProjectCard (input: {cardId: $cardId columnId: $columnId}) { + cardEdge { + node { + resourcePath + } + } + } + } + ` + let issue = ${{steps.update-prework-issue-status.outputs.result}} + if (issue != false) { + let cardId = issue.projectCards.nodes[0].id + return await github.graphql(mutation, { + cardId: cardId, + columnId: projectColumnId, + }) + } + + - name: Leave comment on issue + uses: actions/github-script@v7 + with: + script: | + const script = require('./github-actions/prework_issue_comment/add-prework-comment.js') + const issue = ${{steps.get-prework-issue.outputs.result}} + const activityDetail = ${{steps.get-activity-detail.outputs.result}} + return script({ g: github, c: context}, issue.number, activityDetail) \ No newline at end of file From fdf0c9c8bc665b5ffd59dbde056bed0302059d45 Mon Sep 17 00:00:00 2001 From: partapparam Date: Mon, 20 May 2024 18:21:06 -0700 Subject: [PATCH 04/10] issue comment trigger --- .github/workflows/issue-comment-trigger.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/workflows/issue-comment-trigger.yaml diff --git a/.github/workflows/issue-comment-trigger.yaml b/.github/workflows/issue-comment-trigger.yaml new file mode 100644 index 0000000000..e973a86cec --- /dev/null +++ b/.github/workflows/issue-comment-trigger.yaml @@ -0,0 +1,13 @@ +name: Issue Comment Trigger +on: + issue_comment: + types: + - created + +jobs: + Add-Comment-To-Prework-Issue: + if: ${{ github.event_name == 'issue_comment' && github.event.action == 'created'}} + permissions: + issues: write + uses: partapparam/website/.github/workflows/prework-issue-comment-reusable-workflow.yaml@gh-pages + secrets: inherit \ No newline at end of file From 62afa134e01c309ac74c591416c436e5840ba75a Mon Sep 17 00:00:00 2001 From: partapparam Date: Mon, 20 May 2024 18:23:00 -0700 Subject: [PATCH 05/10] added pr trigger --- .github/workflows/pull-request-trigger.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull-request-trigger.yml b/.github/workflows/pull-request-trigger.yml index 3a11ba65fc..30cafa4749 100644 --- a/.github/workflows/pull-request-trigger.yml +++ b/.github/workflows/pull-request-trigger.yml @@ -64,4 +64,11 @@ jobs: project: Project Board column: 'PR Needs review (Automated Column, do not place items here manually)' repo-token: ${{ secrets.HACKFORLA_BOT_PA_TOKEN }} - action: delete \ No newline at end of file + action: delete + + Add-Comment-To-Prework-Issue: + if: ${{ github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'closed')}} + permissions: + issues: write + uses: ./.github/workflows/prework-issue-comment-reusable-workflow.yaml@gh-pages + secrets: inherit \ No newline at end of file From 438d12f9d3521f5de0256a589314e08a6dd8f0a7 Mon Sep 17 00:00:00 2001 From: partapparam Date: Mon, 20 May 2024 18:24:49 -0700 Subject: [PATCH 06/10] update workflow path --- .github/workflows/issue-comment-trigger.yaml | 3 +-- .github/workflows/issue-trigger.yml | 2 +- .github/workflows/pull-request-trigger.yml | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/issue-comment-trigger.yaml b/.github/workflows/issue-comment-trigger.yaml index e973a86cec..38d9cad917 100644 --- a/.github/workflows/issue-comment-trigger.yaml +++ b/.github/workflows/issue-comment-trigger.yaml @@ -9,5 +9,4 @@ jobs: if: ${{ github.event_name == 'issue_comment' && github.event.action == 'created'}} permissions: issues: write - uses: partapparam/website/.github/workflows/prework-issue-comment-reusable-workflow.yaml@gh-pages - secrets: inherit \ No newline at end of file + uses: ./.github/workflows/prework-issue-comment-reusable-workflow.yaml secrets: inherit \ No newline at end of file diff --git a/.github/workflows/issue-trigger.yml b/.github/workflows/issue-trigger.yml index 66c1872a35..9b902572ac 100644 --- a/.github/workflows/issue-trigger.yml +++ b/.github/workflows/issue-trigger.yml @@ -117,5 +117,5 @@ jobs: if: "${{ github.event.action == 'opened' || github.event.action == 'closed' || github.event.action == 'assigned' || github.event.action == 'unassigned'}}" permissions: issues: write - uses: partapparam/website/.github/workflows/prework-issue-comment-reusable-workflow.yaml@gh-pages + uses: ./.github/workflows/prework-issue-comment-reusable-workflow.yaml secrets: inherit diff --git a/.github/workflows/pull-request-trigger.yml b/.github/workflows/pull-request-trigger.yml index 30cafa4749..4218c46485 100644 --- a/.github/workflows/pull-request-trigger.yml +++ b/.github/workflows/pull-request-trigger.yml @@ -70,5 +70,5 @@ jobs: if: ${{ github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'closed')}} permissions: issues: write - uses: ./.github/workflows/prework-issue-comment-reusable-workflow.yaml@gh-pages + uses: ./.github/workflows/prework-issue-comment-reusable-workflow.yaml secrets: inherit \ No newline at end of file From bca7b974651c9d76e19379a6a938b7d0eb62f6d7 Mon Sep 17 00:00:00 2001 From: partapparam Date: Mon, 20 May 2024 23:14:40 -0700 Subject: [PATCH 07/10] triggers --- .github/workflows/issue-comment-trigger.yaml | 5 +++-- .../pull-request-review-comment-trigger.yaml | 12 ++++++++++++ .github/workflows/pull-request-review-trigger.yaml | 12 ++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/pull-request-review-comment-trigger.yaml create mode 100644 .github/workflows/pull-request-review-trigger.yaml diff --git a/.github/workflows/issue-comment-trigger.yaml b/.github/workflows/issue-comment-trigger.yaml index 38d9cad917..31ab11e6c8 100644 --- a/.github/workflows/issue-comment-trigger.yaml +++ b/.github/workflows/issue-comment-trigger.yaml @@ -2,11 +2,12 @@ name: Issue Comment Trigger on: issue_comment: types: - - created + - created jobs: Add-Comment-To-Prework-Issue: if: ${{ github.event_name == 'issue_comment' && github.event.action == 'created'}} permissions: issues: write - uses: ./.github/workflows/prework-issue-comment-reusable-workflow.yaml secrets: inherit \ No newline at end of file + uses: ./.github/workflows/prework-issue-comment-reusable-workflow.yaml + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/pull-request-review-comment-trigger.yaml b/.github/workflows/pull-request-review-comment-trigger.yaml new file mode 100644 index 0000000000..6248ca4bd1 --- /dev/null +++ b/.github/workflows/pull-request-review-comment-trigger.yaml @@ -0,0 +1,12 @@ +name: Pull Request Review Comment Trigger +on: + pull_request_review_comment: + types: + - created +jobs: + Add-Comment-To-Prework-Issue: + if: ${{ github.event_name == 'pull_request_review_comment' && github.event.action == 'created'}} + permissions: + issues: write + uses: ./.github/workflows/prework-issue-comment-reusable-workflow.yaml + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/pull-request-review-trigger.yaml b/.github/workflows/pull-request-review-trigger.yaml new file mode 100644 index 0000000000..bf127e56df --- /dev/null +++ b/.github/workflows/pull-request-review-trigger.yaml @@ -0,0 +1,12 @@ +name: Pull Request Review Trigger +on: + pull_request_review: + types: + - submitted +jobs: + Add-Comment-To-Prework-Issue: + if: ${{ github.event_name == 'pull_request_review' && github.event.action == 'submitted'}} + permissions: + issues: write + uses: ./.github/workflows/prework-issue-comment-reusable-workflow.yaml + secrets: inherit \ No newline at end of file From 411d9229d823908f5e8851b34cab0e333ef5f228 Mon Sep 17 00:00:00 2001 From: partapparam Date: Mon, 20 May 2024 23:23:27 -0700 Subject: [PATCH 08/10] updates --- .../update-prework-issue-status.js | 2 +- github-actions/utils/get-issue-by-label.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/github-actions/prework-issue-reusable-workflow/update-prework-issue-status.js b/github-actions/prework-issue-reusable-workflow/update-prework-issue-status.js index 436dd8da81..32063a9203 100644 --- a/github-actions/prework-issue-reusable-workflow/update-prework-issue-status.js +++ b/github-actions/prework-issue-reusable-workflow/update-prework-issue-status.js @@ -17,7 +17,7 @@ async function main({ g, c }, issue) { // TODO value is hardcoded // Project Number =1 , for HFLA project number = 7 - const projectColumnId = "PC_lATOJyGIJc4A4juVzgEvcLk" + const projectColumnId = "PC_lATOLVwEr84A4jIbzgEvVeo" console.log(issue) if (issue.closed == true) { const result = await reopenIssue(issue.id, github) diff --git a/github-actions/utils/get-issue-by-label.js b/github-actions/utils/get-issue-by-label.js index 5617cb6259..e202c8a42f 100644 --- a/github-actions/utils/get-issue-by-label.js +++ b/github-actions/utils/get-issue-by-label.js @@ -12,6 +12,7 @@ async function getIssueByLabel(actor, labels, github, context) { owner: "partapparam", repository: "website", }) + console.log(context) let issue = results.repository.issues.nodes[0] return issue From 16bdda7aa41d709820d18a161674bb4f489f2043 Mon Sep 17 00:00:00 2001 From: partapparam Date: Tue, 21 May 2024 11:02:22 -0700 Subject: [PATCH 09/10] made updates to names and checking for false values --- ...ework-issue-comment-reusable-workflow.yaml | 33 +++++++++---------- .../update-prework-issue-status.js | 1 - github-actions/utils/get-issue-by-label.js | 8 ++--- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/.github/workflows/prework-issue-comment-reusable-workflow.yaml b/.github/workflows/prework-issue-comment-reusable-workflow.yaml index 738d26d965..6f4ba66c4e 100644 --- a/.github/workflows/prework-issue-comment-reusable-workflow.yaml +++ b/.github/workflows/prework-issue-comment-reusable-workflow.yaml @@ -4,7 +4,7 @@ on: workflow_call: jobs: - Add-Comment-To-Prework-Issue: + Add-Comment-To-Prework-Issue-Reusable: runs-on: ubuntu-latest permissions: issues: write @@ -27,6 +27,9 @@ jobs: script: | const script = require('./github-actions/prework-issue-reusable-workflow/get-prework-issue.js') const activityDetail = ${{steps.get-activity-detail.outputs.result}} + if (!activityDetail) { + return false + } return script({g: github, c: context}, activityDetail) - name: Update prework issue status @@ -37,28 +40,22 @@ jobs: script: | const script = require('./github-actions/prework-issue-reusable-workflow/update-prework-issue-status.js') const issue = ${{steps.get-prework-issue.outputs.result}} - return script({g: github, c: context}, issue) + if (issue) { + return script({g: github, c: context}, issue) + } + return false # Only move issue if issue was closed and is reopened - name: Move issue uses: actions/github-script@v7 with: github-token: ${{ secrets.HFLA_PROJECT_BOARD_TOKEN }} + # NOTE: The projectColumnId is hard-coded script: | - const projectColumnId = "PC_lATOJyGIJc4A4juVzgEvcLk" - let mutation = ` - mutation ($cardId: ID! $columnId: ID!) { - moveProjectCard (input: {cardId: $cardId columnId: $columnId}) { - cardEdge { - node { - resourcePath - } - } - } - } - ` - let issue = ${{steps.update-prework-issue-status.outputs.result}} - if (issue != false) { + const projectColumnId = "MDEzOlByb2plY3RDb2x1bW43MTk4MjI4" + const issue = ${{steps.update-prework-issue-status.outputs.result}} + const script = require('./github-actions/utils/update-issue-project-card.js') + if (issue) { let cardId = issue.projectCards.nodes[0].id return await github.graphql(mutation, { cardId: cardId, @@ -73,4 +70,6 @@ jobs: const script = require('./github-actions/prework_issue_comment/add-prework-comment.js') const issue = ${{steps.get-prework-issue.outputs.result}} const activityDetail = ${{steps.get-activity-detail.outputs.result}} - return script({ g: github, c: context}, issue.number, activityDetail) \ No newline at end of file + if (issue && activityDetail) { + script({ g: github, c: context}, issue.number, activityDetail) + } \ No newline at end of file diff --git a/github-actions/prework-issue-reusable-workflow/update-prework-issue-status.js b/github-actions/prework-issue-reusable-workflow/update-prework-issue-status.js index 32063a9203..56d4fb3e4d 100644 --- a/github-actions/prework-issue-reusable-workflow/update-prework-issue-status.js +++ b/github-actions/prework-issue-reusable-workflow/update-prework-issue-status.js @@ -17,7 +17,6 @@ async function main({ g, c }, issue) { // TODO value is hardcoded // Project Number =1 , for HFLA project number = 7 - const projectColumnId = "PC_lATOLVwEr84A4jIbzgEvVeo" console.log(issue) if (issue.closed == true) { const result = await reopenIssue(issue.id, github) diff --git a/github-actions/utils/get-issue-by-label.js b/github-actions/utils/get-issue-by-label.js index e202c8a42f..0067bf7e0b 100644 --- a/github-actions/utils/get-issue-by-label.js +++ b/github-actions/utils/get-issue-by-label.js @@ -5,15 +5,13 @@ */ async function getIssueByLabel(actor, labels, github, context) { try { - // TODO - How to get owner and repo dynamically + const [owner, name] = context.payload.repository.full_name.split("/") let results = await github.graphql(query, { actor: actor, labels: labels, - owner: "partapparam", - repository: "website", + owner: owner, + repository: name, }) - console.log(context) - let issue = results.repository.issues.nodes[0] return issue } catch (err) { From 0ae212b648ae73448fc7b2ac8756dc7e96b57a0f Mon Sep 17 00:00:00 2001 From: partapparam Date: Tue, 21 May 2024 11:09:58 -0700 Subject: [PATCH 10/10] tokens --- .../prework-issue-comment-reusable-workflow.yaml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/prework-issue-comment-reusable-workflow.yaml b/.github/workflows/prework-issue-comment-reusable-workflow.yaml index 6f4ba66c4e..4d65ddc504 100644 --- a/.github/workflows/prework-issue-comment-reusable-workflow.yaml +++ b/.github/workflows/prework-issue-comment-reusable-workflow.yaml @@ -36,7 +36,7 @@ jobs: id: update-prework-issue-status uses: actions/github-script@v7 with: - github-token: ${{ secrets.HFLA_PROJECT_BOARD_TOKEN }} + github-token: ${{ secrets.HACKFORLA_BOT_PA_TOKEN }} script: | const script = require('./github-actions/prework-issue-reusable-workflow/update-prework-issue-status.js') const issue = ${{steps.get-prework-issue.outputs.result}} @@ -49,18 +49,15 @@ jobs: - name: Move issue uses: actions/github-script@v7 with: - github-token: ${{ secrets.HFLA_PROJECT_BOARD_TOKEN }} + github-token: ${{ secrets.HACKFORLA_BOT_PA_TOKEN }} # NOTE: The projectColumnId is hard-coded script: | const projectColumnId = "MDEzOlByb2plY3RDb2x1bW43MTk4MjI4" const issue = ${{steps.update-prework-issue-status.outputs.result}} const script = require('./github-actions/utils/update-issue-project-card.js') if (issue) { - let cardId = issue.projectCards.nodes[0].id - return await github.graphql(mutation, { - cardId: cardId, - columnId: projectColumnId, - }) + const issueCardId = issue.projectCards.nodes[0].id + script(issueCardId, projectColumnId, github) } - name: Leave comment on issue