-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added code to automatically update contributors
- Loading branch information
Showing
6 changed files
with
216 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,43 @@ | ||
{ | ||
"projectName": "cs249r_book", | ||
"projectOwner": "harvard-edge", | ||
"files": [ | ||
"contributors.qmd", "README.md" | ||
], | ||
"contributors": [ | ||
{ | ||
"login": "jveejay", | ||
"name": "Vijay Janapa Reddi", | ||
"avatar_url": "https://avatars.githubusercontent.com/jveejay", | ||
"profile": "https://github.com/jveejay", | ||
"contributions": [ | ||
"doc" | ||
] | ||
}, | ||
{ | ||
"login": "mpstewart1", | ||
"name": "Matthew Stewart", | ||
"avatar_url": "https://avatars.githubusercontent.com/mpstewart1", | ||
"profile": "https://github.com/mpstewart1", | ||
"contributions": [ | ||
"doc" | ||
] | ||
}, | ||
{ | ||
"login": "uchendui", | ||
"name": "Ikechukwu Uchendu", | ||
"avatar_url": "https://avatars.githubusercontent.com/uchendui", | ||
"profile": "https://github.com/uchendui", | ||
"contributions": [ | ||
"doc" | ||
] | ||
} | ||
], | ||
"repoType": "github", | ||
"contributorsPerLine": 7, | ||
"repoHost": "https://github.com", | ||
"commitConvention": "angular", | ||
"skipCi": true, | ||
"commitType": "docs" | ||
} | ||
"projectName": "cs249r_book", | ||
"projectOwner": "harvard-edge", | ||
"files": [ | ||
"contributors.qmd", | ||
"README.md" | ||
], | ||
"contributors": [ | ||
{ | ||
"login": "jveejay", | ||
"name": "Vijay Janapa Reddi", | ||
"avatar_url": "https://avatars.githubusercontent.com/jveejay", | ||
"profile": "https://github.com/jveejay", | ||
"contributions": [ | ||
"doc" | ||
] | ||
}, | ||
{ | ||
"login": "uchendui", | ||
"name": "Ikechukwu Uchendu", | ||
"avatar_url": "https://avatars.githubusercontent.com/uchendui", | ||
"profile": "https://github.com/uchendui", | ||
"contributions": [ | ||
"doc" | ||
] | ||
}, | ||
{ | ||
"login": "mpstewart1", | ||
"name": "Matthew Stewart", | ||
"avatar_url": "https://avatars.githubusercontent.com/mpstewart1", | ||
"profile": "https://github.com/mpstewart1", | ||
"contributions": [ | ||
"doc" | ||
] | ||
} | ||
], | ||
"repoType": "github", | ||
"contributorsPerLine": 7, | ||
"repoHost": "https=//github.com", | ||
"commitConvention": "angular", | ||
"skipCi": true, | ||
"commitType": "docs" | ||
} |
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,61 @@ | ||
name: Automatically Add Contributors | ||
run-name: ${{ github.actor }} is updating TinyML book contributors | ||
on: | ||
push: | ||
branches: | ||
auto_contributor | ||
|
||
jobs: | ||
update-contributors: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Setup Python3.11 | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.11 | ||
|
||
- name: Installing GitHub CLI | ||
run: | | ||
sudo apt install -y gh jq nodejs npm | ||
- name: Install python packages | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r .github/workflows/contributors/requirements.txt | ||
- name: Retrieving contributors for commit ${{ github.sha }} | ||
run: | | ||
echo "π The job was automatically triggered by a ${{ github.event_name }} event." | ||
echo "π§ This job is now running on a ${{ runner.os }} server hosted by GitHub!" | ||
echo "π Getting all contributors from the ${{ github.ref }} branch." | ||
PUSHED_CONTRIBUTORS=$(git shortlog -sne --no-merges ${{ github.event.before }}..${{ github.sha }}) | ||
echo "The contributors are: $PUSHED_CONTRIBUTORS" | ||
- name: Running Python Script to Update .all-contributorsrc | ||
run: | | ||
echo "Running Python Script to Update .all-contributorsrc" | ||
python .github/workflows/contributors/update_contributors.py | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Committing changes to same branch | ||
run: | | ||
echo "Committing changes to same branch" | ||
git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
git config --global user.name "github-actions[bot]" | ||
git add .all-contributorsrc | ||
git commit -m " Update contributors from github action" | ||
git push | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Using all-contributors CLI to update files | ||
run: | | ||
echo "Using all-contributors CLI to update files" | ||
npm i -D all-contributors-cli | ||
npx all-contributors generate | ||
git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
git config --global user.name "github-actions[bot]" | ||
git add -u | ||
git commit -m "Update readme and contributors.qmd with contributors" | ||
git push |
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,3 @@ | ||
absl-py | ||
pandas | ||
PyGithub |
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,104 @@ | ||
import json | ||
import os | ||
|
||
from absl import app | ||
from github import Github | ||
import requests | ||
|
||
CONTRIBUTORS_TMP_FILE = 'CONTRIBUTORS_TEMP.txt' | ||
CONTRIBUTORS_FILE = '.all-contributorsrc' | ||
|
||
EXCLUDED_USERS = ['web-flow'] | ||
|
||
OWNER = "harvard-edge" | ||
REPO = "cs249r_book" | ||
BRANCH = "auto_contributor" | ||
|
||
|
||
def split_name_email(s): | ||
parts = s.rsplit(' ', 1) | ||
return parts[0], parts[1][1:-1] # Removing angle brackets from email | ||
|
||
|
||
def get_github_username(token, email): | ||
g = Github(token) | ||
users = g.search_users(email) | ||
for user in users: | ||
# Assuming the first user returned with the matching email is the correct user | ||
return user.login | ||
return None | ||
|
||
|
||
def main(_): | ||
token = os.environ["GH_TOKEN"] | ||
|
||
headers = { | ||
"Authorization": f"token {token}" | ||
} | ||
|
||
web_address = f'https://api.github.com/repos/{OWNER}/{REPO}/commits?sha={BRANCH}&per_page=100' | ||
res = requests.get(web_address, headers=headers) | ||
|
||
print(web_address) | ||
|
||
# Check if the request was successful | ||
if res.status_code == 200: | ||
# Parse the JSON response | ||
data = res.json() | ||
|
||
# Extract the 'login' attribute for each committer | ||
usernames = [commit['committer']['login'] for commit in data if commit['committer']] | ||
|
||
# Print unique usernames | ||
for username in sorted(set(usernames)): | ||
print(username) | ||
|
||
with open(CONTRIBUTORS_FILE, 'r') as contrib_file: | ||
contributors_data = json.load(contrib_file) | ||
user_to_name_dict = dict() | ||
contributors = contributors_data['contributors'] | ||
|
||
contributor_logins = [] | ||
for contrib in contributors: | ||
user_to_name_dict[contrib['login']] = contrib['name'] | ||
contributor_logins.append(contrib['login']) | ||
contributor_logins_set = set(contributor_logins) | ||
|
||
# Perform the set subtraction | ||
# result = usernames_set - contributor_logins_set | ||
result = contributor_logins_set - set(EXCLUDED_USERS) | ||
|
||
print('New contributors: ', result) | ||
|
||
final_result = dict( | ||
projectName=REPO, | ||
projectOwner=OWNER, | ||
files=["contributors.qmd", "README.md"], | ||
contributors=[dict(login=user, | ||
name=user_to_name_dict[user], | ||
avatar_url=f'https://avatars.githubusercontent.com/{user}', | ||
profile=f'https://github.com/{user}', | ||
contributions=['doc'], ) for | ||
user in result], | ||
|
||
repoType='github', | ||
contributorsPerLine=7, | ||
repoHost="https=//github.com", | ||
commitConvention='angular', | ||
skipCi=True, | ||
commitType="docs" | ||
) | ||
|
||
print(final_result) | ||
json_string = json.dumps(final_result, | ||
indent=4) # The indent parameter is optional, but it formats the output to be more readable | ||
print(json_string) | ||
|
||
with open(CONTRIBUTORS_FILE, 'w') as contrib_file: | ||
contrib_file.write(json_string) | ||
else: | ||
print(f"Failed with status code: {res.status_code}") | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run(main) |
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
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