-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into PIMS-2106-nginx
- Loading branch information
Showing
33 changed files
with
2,058 additions
and
1,280 deletions.
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
21 changes: 0 additions & 21 deletions
21
.github/helpers/github-api/create-and-close-existing-issue.mjs
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,47 +1,16 @@ | ||
/** | ||
* Reusable functions for making requests to the GitHub REST API. | ||
* @author Brady Mitchell <[email protected] | [email protected]> | ||
* API Documentation: https://octokit.github.io/rest.js/v19#usage | ||
* @editor Taylor Friesen <[email protected]> | ||
* API Documentation: https://docs.github.com/en/rest | ||
* | ||
* THIS FILE DOES NOT NEED TO BE EDITED, but you can add more functions if desired. | ||
* Place within .github/helpers/github-api/ | ||
* | ||
* - Be sure to include the env variables from below! | ||
* | ||
* @example GitHub Actions Workflow: | ||
* jobs: | ||
* github-api: | ||
* runs-on: ubuntu-22.04 | ||
* container: | ||
* image: node:20.2-bullseye-slim | ||
* | ||
* steps: | ||
* # Checkout branch. | ||
* - name: Checkout repository | ||
* uses: actions/checkout@v3 | ||
* | ||
* # Get Repo Owner and Repo Name. | ||
* - name: Set repo information | ||
* run: | | ||
* echo "REPO_OWNER=$(echo ${{ github.repository }} | cut -d / -f 1)" >> $GITHUB_ENV | ||
* echo "REPO_NAME=$(echo ${{ github.repository }} | cut -d / -f 2)" >> $GITHUB_ENV | ||
* | ||
* # Install @octokit/rest npm package for making GitHub rest API requests. | ||
* - name: Install @octokit/rest npm | ||
* run: npm i @octokit/rest | ||
* | ||
* # Run Node Script that calls functions from github-api-requests.js. | ||
* - name: Node Script | ||
* env: | ||
* GITHUB_OWNER: ${{ env.REPO_OWNER }} | ||
* GITHUB_REPO: ${{ env.REPO_NAME }} | ||
* GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
* run: node .github/helpers/script.js | ||
*/ | ||
|
||
import { Octokit } from '@octokit/rest'; | ||
import { Octokit } from "@octokit/rest"; | ||
const { GITHUB_TOKEN, GITHUB_REPOSITORY } = process.env; | ||
const [GITHUB_OWNER, GITHUB_REPO] = GITHUB_REPOSITORY.split('/'); | ||
const [GITHUB_OWNER, GITHUB_REPO] = GITHUB_REPOSITORY.split("/"); | ||
|
||
// Create a personal access token at https://github.com/settings/tokens/new?scopes=repo | ||
const octokit = new Octokit({ auth: GITHUB_TOKEN }); | ||
|
@@ -50,64 +19,97 @@ const octokit = new Octokit({ auth: GITHUB_TOKEN }); | |
* Create an Issue with the GitHub REST API. | ||
* @param {string} title - The title for the new issue. | ||
* @param {string} body - The content body for the new issue. | ||
* @returns request.data - Data returned by the request. | ||
* @returns - response - returned response from github. | ||
* @example | ||
* createIssue('My Issue', 'An example issue'); | ||
*/ | ||
export async function createIssue(title, body) { | ||
const request = await octokit.rest.issues.create({ | ||
owner: GITHUB_OWNER, | ||
repo: GITHUB_REPO, | ||
title, | ||
body, | ||
}); | ||
console.log(request.data); | ||
return request; | ||
const response = await octokit.rest.issues.create({ | ||
owner: GITHUB_OWNER, | ||
repo: GITHUB_REPO, | ||
title, | ||
body, | ||
}); | ||
//console.log("create issue: ", response.data); | ||
return response; | ||
} | ||
|
||
/** | ||
* Close an Issue with the GitHub REST API. | ||
* @param {number} issue_number - The id for a GitHub Issue. | ||
* @returns request.data - Data returned by the request. | ||
* @returns - response - returned response from github. | ||
* @example | ||
* closeIssue(1044); | ||
*/ | ||
export async function closeIssue(issue_number) { | ||
const request = await octokit.rest.issues.update({ | ||
owner: GITHUB_OWNER, | ||
repo: GITHUB_REPO, | ||
issue_number, | ||
state: 'closed', | ||
}); | ||
console.log(request.data); | ||
return request; | ||
const response = await octokit.rest.issues.update({ | ||
owner: GITHUB_OWNER, | ||
repo: GITHUB_REPO, | ||
issue_number, | ||
state: "closed", | ||
}); | ||
//console.log("close issue: ", response.data); | ||
return response; | ||
} | ||
|
||
/** | ||
* Get issue number from title, and create a request to add a comment. | ||
* @param {*} issueNumber - the number for the issue to comment on | ||
* @param {*} issueComment - the comment to add | ||
* @returns - response - returned response from github. | ||
* @example | ||
* addComment(1234, 'An example comment'); | ||
*/ | ||
export async function addComment(issueNumber, issueComment) { | ||
const response = await octokit.rest.issues.createComment({ | ||
owner: GITHUB_OWNER, | ||
repo: GITHUB_REPO, | ||
issue_number: issueNumber, | ||
body: issueComment, | ||
}); | ||
//console.log("add comment: ", response.data); | ||
return response; | ||
} | ||
|
||
/** | ||
* Close a comment on an issue by referencing the ID | ||
* @param {*} commentID - the number associated with a comment | ||
* @returns - response - returned response from github. | ||
* @example | ||
* deleteComment(1234); | ||
*/ | ||
export async function deleteComment(commentID) { | ||
const response = await octokit.rest.issues.deleteComment({ | ||
owner: GITHUB_OWNER, | ||
repo: GITHUB_REPO, | ||
comment_id: commentID, | ||
}); | ||
//console.log("delete comment: ", response.data); | ||
return response; | ||
} | ||
|
||
/** | ||
* 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. | ||
* @param {string} state - (optional, default=open) Search for all, open, or closed issues. | ||
* @returns issue.number or null | ||
* @returns response from Github | ||
* @example | ||
* findIssueByTitle('My Issue'); | ||
*/ | ||
export async function findIssueByTitle(title, state = 'open') { | ||
const { data: issues } = await octokit.rest.issues.listForRepo({ | ||
owner: GITHUB_OWNER, | ||
repo: GITHUB_REPO, | ||
state, // Get issues that are 'open', 'closed' or 'all'. | ||
}); | ||
|
||
for (const issue of issues) { | ||
if (issue.title === title) { | ||
return issue.number; | ||
} | ||
} | ||
return null; // Return null if no issue found. | ||
export async function findIssues(state = "open") { | ||
const response = await octokit.rest.issues.listForRepo({ | ||
owner: GITHUB_OWNER, | ||
repo: GITHUB_REPO, | ||
state, // Get issues that are 'open', 'closed' or 'all'. | ||
}); | ||
//console.log("found issue: ", response.data); | ||
return response; | ||
} | ||
|
||
export default { | ||
createIssue, | ||
closeIssue, | ||
findIssueByTitle, | ||
createIssue, | ||
closeIssue, | ||
addComment, | ||
deleteComment, | ||
findIssues, | ||
}; |
Oops, something went wrong.