Skip to content

Commit

Permalink
add comment when adding issue
Browse files Browse the repository at this point in the history
  • Loading branch information
TaylorFries committed Nov 6, 2024
1 parent 6ad1128 commit b34b790
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createIssue, closeIssue, findIssueByTitle } from './github-api-requests
* Place within .github/helpers/github-api/
*/

export const createAndCloseExistingIssue = async (issueTitle, issueBody) => {
export const createAndCloseExistingIssue = async (issueTitle, issueBody, issueComment) => {
// Check for existing Issue.
const existingIssueNumber = await findIssueByTitle(issueTitle);

Expand All @@ -16,6 +16,9 @@ export const createAndCloseExistingIssue = async (issueTitle, issueBody) => {

// Create new Issue.
await createIssue(issueTitle, decodeURIComponent(issueBody));

// Add comment to Issue.
await addComment(issueTitle, issueComment);
};

export default createAndCloseExistingIssue;
21 changes: 21 additions & 0 deletions .github/helpers/github-api/github-api-requests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,27 @@ export async function closeIssue(issue_number) {
return request;
}

/**
* Get issue number from title, and create a request to add a comment.
* @param {*} issueTitle - the title of the comment to comment on
* @param {*} issueComment - the comment to add
* @returns - requestData - Data returned by the request.
* @example
* addComment('My Issue', 'An example comment');
*/
export async function addComment(issueTitle, issueComment) {
const issueNumber = findIssueByTitle(issueTitle);

const request = await octokit.rest.issues.createComment({
owner: GITHUB_OWNER,
repo: GITHUB_REPO,
issueNumber,
body: issueComment,
});
console.log(request.data);
return request;
}

/**
* Find an Issue's ID number with the GitHub REST API, given a title.
* @param {string} title - The title of the issue to search for.
Expand Down
3 changes: 2 additions & 1 deletion .github/helpers/npm-deps/create-report-issues.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const outputText = require(path.resolve(__dirname, `../../../outputText.json`));

// Get package.json paths from env.
const packageJsonPaths = JSON.parse(process.env.packageJsonPaths);
const comment = JSON.parse(process.env.commentContents);

(async () => {
const module = await import('../github-api/create-and-close-existing-issue.mjs');
Expand All @@ -17,7 +18,7 @@ const packageJsonPaths = JSON.parse(process.env.packageJsonPaths);
const issueTitle =
packagePath !== '.' ? `${packagePath} NPM Dependency Report` : 'NPM Dependency Report';
// Await the completion of create and close existing issue.
await createAndCloseExistingIssue(issueTitle, outputText[packagePath]);
await createAndCloseExistingIssue(issueTitle, outputText[packagePath], comment);
});

// Wait for all issues to be created.
Expand Down
2 changes: 1 addition & 1 deletion .github/helpers/npm-deps/parse_to_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def main():
github_env = os.getenv('GITHUB_ENV')
# write retults to file
with open(github_env, "a", encoding="utf-8") as env_file:
env_file.write("COMMENT=" + update_str)
env_file.write("commentContents=" + update_str)

# log end
log(EXIT_CODE, "Sript has completed")
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/app-npm-dep-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ jobs:
with:
name: outdatedDeps
path: .

# encode file to github needs
- name: Encode Outdated Deps
shell: bash
Expand All @@ -93,24 +94,23 @@ jobs:
OUTPUT="${OUTPUT//$'\n'/'%0A'}"
OUTPUT="${OUTPUT//$'\r'/'%0D'}"
echo "DEP_INPUT=${OUTPUT}" >> $GITHUB_ENV
# checkout repo and branch
- name: Checkout Branch
uses: actions/checkout@v3

# setup Python environment
- name: setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11' # current Python version

# Run Python Script to Create Comment
- name: Create Comment Contents
env:
DEP_INPUT: ${{ env.DEP_INPUT }} # dependency updates
run: |
python3 .github/helpers/npm-deps/parse_to_comment.py
- name: Test comment
run: |
echo $COMMENT
# Write the output text for the GitHub Issue.
write-output:
Expand Down Expand Up @@ -153,6 +153,7 @@ jobs:
create-issues:
needs:
- parse-json5-config
- create-comment-text
- write-output
runs-on: ubuntu-22.04
env:
Expand Down

0 comments on commit b34b790

Please sign in to comment.