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

Verify that PR creator is a member of the website-write team #6971

Draft
wants to merge 45 commits into
base: gh-pages
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
9fe8e0e
Add Instructions
ajb176 May 30, 2024
1602ec4
Fix formatting
ajb176 May 31, 2024
1bb8ac4
Fix formatting
ajb176 May 31, 2024
dbd114f
Merge pull request #49 from ajb176/gh-pages
ajb176 May 31, 2024
c3d5f8d
Merge branch 'gh-pages' of https://github.com/hackforla/website into …
ajb176 May 31, 2024
c96bf31
Merge branch 'gh-pages' of https://github.com/hackforla/website into …
ajb176 Jun 5, 2024
081bf9a
Testing change from github-token to repo-token
ajb176 Jun 5, 2024
12a897d
Changing github-token
ajb176 Jun 6, 2024
f67436d
Create new yml file
ajb176 Jun 6, 2024
709d65c
Merge branch 'gh-pages' of https://github.com/hackforla/website into …
ajb176 Jun 6, 2024
1843799
re-formatting
ajb176 Jun 6, 2024
daa2e4b
restoring original
ajb176 Jun 6, 2024
744cdf2
Merge branch 'gh-pages' of https://github.com/hackforla/website into …
ajb176 Jun 18, 2024
e8dff76
Change Format
ajb176 Jun 20, 2024
2ade79c
.
ajb176 Jun 20, 2024
3f7b909
test
ajb176 Jun 20, 2024
0bb78b2
.
ajb176 Jun 20, 2024
8ff8dc3
fix typo
ajb176 Jun 20, 2024
7e37309
add checkout
ajb176 Jun 20, 2024
c1c3f46
l
ajb176 Jun 20, 2024
a8a9b15
d
ajb176 Jun 20, 2024
321d2f6
.
ajb176 Jun 20, 2024
dca3a85
fix
ajb176 Jun 20, 2024
0e296a6
.
ajb176 Jun 20, 2024
ae0e961
.
ajb176 Jun 20, 2024
36cc8b7
l
ajb176 Jun 21, 2024
6a691d1
fix
ajb176 Jun 21, 2024
6ba49a9
Add utility function, change API syntax
ajb176 Jun 21, 2024
f6bd3ee
fix comment body
ajb176 Jun 21, 2024
b9f9ca3
Remove unit testing code from utility function
ajb176 Jun 21, 2024
401d6e1
Merge branch 'gh-pages' of https://github.com/hackforla/website into …
ajb176 Jul 30, 2024
3db8b69
Merge branch 'gh-pages' of https://github.com/hackforla/website into …
ajb176 Jul 30, 2024
e3e6336
Remove Branches
ajb176 Jul 31, 2024
77be869
formatting
ajb176 Jul 31, 2024
2d5e4c4
Remove console log
ajb176 Jul 31, 2024
321c05c
Readying for PR
ajb176 Jul 31, 2024
f96c62d
Fix Capitalization
ajb176 Jul 31, 2024
07e0455
Merge branch 'verify-pr-creator-3906' into verify-pr-creator-util-3906
ajb176 Jul 31, 2024
dba6f39
Remove line
ajb176 Jul 31, 2024
1acaa59
Update check-team-membership.js
ajb176 Jul 31, 2024
23d4031
Merge pull request #76 from ajb176/verify-pr-creator-util-3906
ajb176 Jul 31, 2024
ef2cf97
Add missing declaration
ajb176 Jul 31, 2024
66bc844
Formatting
ajb176 Jul 31, 2024
ba51db2
Remove testing code
ajb176 Jul 31, 2024
80a6daf
Formatting
ajb176 Jul 31, 2024
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
Prev Previous commit
Next Next commit
Add utility function, change API syntax
  • Loading branch information
ajb176 committed Jun 21, 2024
commit 6ba49a919656094fb1cb5c3b0b302613f65e2e23
17 changes: 8 additions & 9 deletions .github/workflows/pr-verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,25 @@ jobs:
const prAuthor = context.payload.sender.login;
const prNumber = context.payload.number;
try {
const getMembershipStatus = await github.rest.teams.getMembershipForUserInOrg({
org: 'hackforla',
team_slug: 'website-write',
username: prAuthor
await github.rest.teams.getMembershipForUserInOrg({
org: 'hackforla',
team_slug: 'website-write',
username: prAuthor
});
console.log('Successfully verified!')
} catch (verificationError) {
if (verificationError.status==404) {
await github.request('PATCH /repos/{owner}/{repo}/pulls/{pull_number}', {
await github.rest.issues.update({
owner : 'hackforla',
repo : 'website',
pull_number : prNumber,
issue_number : prNumber,
state : 'closed'
});
await github.request('POST /repos/{owner}/{repo}/issues/{issue_number}/comments', {
await github.rest.issues.createComment({
owner : 'hackforla',
repo : 'website',
issue_number : prNumber,
body : 'You must be a member of the HFLA website team in order to create pull requests. Please see our page on how to join us as a member at HFLA: https://www.hackforla.org/getting-started. If you have been though onboarding, and feel this message in error, please message us in the #hfla-site team slack channel with the link to this PR.'
});
}
}

}
33 changes: 33 additions & 0 deletions github-actions/utils/check-team-membership.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @param {octokit} github - Octokit object used to access GitHub API
* @param {String} githubUsername - The github username of the user whose membership is to be checked.
* @param {String} team - The HFLA team the username's membership is checked against. Example: 'website-write'

- Returns true or false depending on whether the username is found on the passed team, 404 means the user passed wasn't
found on the team passed. Any other type of error will be thrown.
- Need read:org permission to use this function, the least permissive token which contains this is the secrets.TEAMS token.
Lack of permission will result in a 403 error.
- The method of obtaining the github username will vary depending on the contents of the context object. See github action
docs on printing context information into the log.
*/

async function isMemberOfTeam(github, githubUsername, team)
{
try {
const result = await github.rest.teams.getMembershipForUserInOrg({
Fixed Show fixed Hide fixed
org : 'hackforla',
team_slug : team,
username : githubUsername
});
return true;
} catch (verificationError) {
if (verificationError.status == 404) {
return false;
}
else {
throw verificationError;
}
}
}

module.exports = isMemberOfTeam;