Skip to content

Commit

Permalink
Auto contributors will now try to merge with main before pushing
Browse files Browse the repository at this point in the history
  • Loading branch information
uchendui committed Sep 27, 2023
1 parent 103b17e commit c28471a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 38 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/auto-add-contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,10 @@ jobs:
python -m pip install --upgrade pip
pip install -r .github/workflows/contributors/requirements.txt
- name: Retrieving all contributors from the main branch
- name: Auto add contributor job has been triggered
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 main)
echo "The contributors are: $PUSHED_CONTRIBUTORS"
- name: Running Python Script to Update .all-contributorsrc
run: |
echo "Running Python Script to Update .all-contributorsrc"
Expand Down
59 changes: 25 additions & 34 deletions .github/workflows/contributors/update_contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,17 @@
import os

from absl import app
from github import Github
import requests

CONTRIBUTORS_FILE = '.all-contributorsrc'

EXCLUDED_USERS = ['web-flow', 'github-actions[bot]', 'mrdragonbear']
EXCLUDED_USERS = {'web-flow', 'github-actions[bot]', 'mrdragonbear'}

OWNER = "harvard-edge"
REPO = "cs249r_book"
BRANCH = "main"


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"]

Expand All @@ -39,35 +24,41 @@ def main(_):
res = requests.get(web_address, headers=headers)

print(web_address)
user_to_name_dict = dict()

# 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)
users_from_api = []
for commit in data:
if commit['committer']:
committer = commit['committer']
users_from_api.append(committer['login'])
user_to_name_dict[committer['login']] = committer['name']
users_from_api = set(users_from_api)
print('Users pulled from API: ', users_from_api)

with open(CONTRIBUTORS_FILE, 'r') as contrib_file:
contributors_data = json.load(contrib_file)
user_to_name_dict = dict()
contributors = contributors_data['contributors']
existing_contributor_data = json.load(contrib_file)
existing_contributors = existing_contributor_data['contributors']

existing_contributor_logins = []
for existing_contributor in existing_contributors:
user_to_name_dict[existing_contributor['login']] = existing_contributor['name']
existing_contributor_logins.append(existing_contributor['login'])
existing_contributor_logins_set = set(existing_contributor_logins)
print('Existing contributors: ', existing_contributor_logins_set)

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)
# All contributors in the file should be in the API
assert existing_contributor_logins_set.issubset(
users_from_api), 'All contributors in the .all-contributorsrc file should be pulled using the API'

# Perform the set subtraction
# result = usernames_set - contributor_logins_set
result = contributor_logins_set - set(EXCLUDED_USERS)
new_contributor_logins = users_from_api - existing_contributor_logins_set
print('New contributors: ', new_contributor_logins)

print('New contributors: ', result)
result = users_from_api - EXCLUDED_USERS

final_result = dict(
projectName=REPO,
Expand Down

0 comments on commit c28471a

Please sign in to comment.