-
-
Notifications
You must be signed in to change notification settings - Fork 797
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
GHA add comments to prework issue 4820 #6873
Closed
partapparam
wants to merge
10
commits into
hackforla:gh-pages
from
partapparam:gha-add-comments-4820
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0c9e435
new-utils
partapparam 6a86c6c
added resuable workflow files
partapparam 4e6dee4
update triggers
partapparam fdf0c9c
issue comment trigger
partapparam 62afa13
added pr trigger
partapparam 438d12f
update workflow path
partapparam bca7b97
triggers
partapparam 411d922
updates
partapparam 16bdda7
made updates to names and checking for false values
partapparam 0ae212b
tokens
partapparam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -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: ./.github/workflows/prework-issue-comment-reusable-workflow.yaml | ||
secrets: inherit |
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
72 changes: 72 additions & 0 deletions
72
.github/workflows/prework-issue-comment-reusable-workflow.yaml
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,72 @@ | ||
name: Find Prework Issue and Comment User Activity | ||
|
||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
Add-Comment-To-Prework-Issue-Reusable: | ||
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}} | ||
if (!activityDetail) { | ||
return false | ||
} | ||
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.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}} | ||
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.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) { | ||
const issueCardId = issue.projectCards.nodes[0].id | ||
script(issueCardId, projectColumnId, github) | ||
} | ||
|
||
- 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}} | ||
if (issue && activityDetail) { | ||
script({ g: github, c: context}, issue.number, activityDetail) | ||
} |
12 changes: 12 additions & 0 deletions
12
.github/workflows/pull-request-review-comment-trigger.yaml
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 @@ | ||
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 |
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 @@ | ||
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 |
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
36 changes: 36 additions & 0 deletions
36
github-actions/prework-issue-reusable-workflow/add-prework-issue-comment.js
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,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<string>} - 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 |
136 changes: 136 additions & 0 deletions
136
github-actions/prework-issue-reusable-workflow/get-activity-detail.js
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,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 |
29 changes: 29 additions & 0 deletions
29
github-actions/prework-issue-reusable-workflow/get-prework-issue.js
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,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 |
29 changes: 29 additions & 0 deletions
29
github-actions/prework-issue-reusable-workflow/update-prework-issue-status.js
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,29 @@ | ||
// 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 | ||
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note