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 3604a6c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 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
60 changes: 31 additions & 29 deletions .github/workflows/contributors/update_contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@

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 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(_):
Expand All @@ -46,28 +46,30 @@ def main(_):
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 = [commit['committer']['login'] for commit in data if commit['committer']]
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)
existing_contributor_data = json.load(contrib_file)
user_to_name_dict = dict()
contributors = contributors_data['contributors']
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 3604a6c

Please sign in to comment.