Skip to content

Commit

Permalink
Use user id instead of login to avoid invalid chars
Browse files Browse the repository at this point in the history
Sometimes the login is a bot account that has the `[bot]` suffix. The brackets causes issues for branch names so using the raw user ID (and integer) is better.
  • Loading branch information
kenodegard committed Sep 10, 2024
1 parent ad3f3c5 commit 6264ecd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
21 changes: 16 additions & 5 deletions check-cla/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,18 @@ def parse_args() -> Namespace:
# parse CLI for inputs
parser = ArgumentParser()
parser.add_argument("cla_path", type=Path, help="Local path to the CLA file.")
parser.add_argument("contributor", type=str, help="Contributor to add to the CLA.")
parser.add_argument(
"--id",
type=int,
required=True,
help="Contributor to add to the CLA.",
)
parser.add_argument(
"--login",
type=str,
required=True,
help="Contributor's GitHub login.",
)
return parser.parse_args()


Expand All @@ -26,10 +37,10 @@ def main() -> None:
try:
signees = json.loads(path.read_text())
except FileNotFoundError:
signees = []
signees.append(args.contributor)
signees.sort(key=str.lower)
path.write_text(json.dumps(signees, indent=2) + "\n")
signees = {}

signees[args.id] = args.login
path.write_text(json.dumps(signees, indent=2, sort_keys=True) + "\n")


if __name__ == "__main__":
Expand Down
24 changes: 15 additions & 9 deletions check-cla/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ runs:
shell: bash

- name: Determine the contributor
run: echo CONTRIBUTOR=${{ github.event.pull_request.user.login || github.event.issue.user.login }} >> $GITHUB_ENV
run: |
echo CONTRIBUTOR_ID=${{ github.event.pull_request.user.id || github.event.issue.user.id }} >> $GITHUB_ENV
echo CONTRIBUTOR_LOGIN=${{ github.event.pull_request.user.login || github.event.issue.user.login }} >> $GITHUB_ENV
shell: bash

- name: Read CLA signees
Expand All @@ -57,10 +59,10 @@ runs:
with:
path: https://raw.githubusercontent.com/${{ inputs.cla_repo }}/main/${{ inputs.cla_path }}
parser: json
default: '[]'
default: '{}'

- name: Determine whether the contributor has signed the CLA
run: echo HAS_SIGNED=${{ contains(fromJSON(steps.read_cla.outputs.content), env.CONTRIBUTOR) }} >> $GITHUB_ENV
run: echo HAS_SIGNED=${{ contains(fromJSON(steps.read_cla.outputs.content), env.CONTRIBUTOR_ID) }} >> $GITHUB_ENV
shell: bash

# if contributor has already signed, add [cla-signed] label
Expand All @@ -86,7 +88,7 @@ runs:
with:
repository: ${{ inputs.cla_repo }}

- name: Create fork
- name: Create CLA fork
if: env.HAS_SIGNED == 'false'
# no-op if the repository is already forked
run: echo FORK=$(gh repo fork --clone=false --default-branch-only 2>&1 | awk '{print $1}') >> $GITHUB_ENV
Expand All @@ -103,7 +105,11 @@ runs:
- name: Add contributor as a CLA signee
if: env.HAS_SIGNED == 'false'
shell: bash
run: python ${{ github.action_path }}/action.py ${{ inputs.cla_path }} ${{ env.CONTRIBUTOR }}
run: >
python ${{ github.action_path }}/action.py
${{ inputs.cla_path }}
--id=${{ env.CONTRIBUTOR_ID }}
--login=${{ env.CONTRIBUTOR_LOGIN }}
# if unsigned, create PR
- name: Create PR with new CLA signee
Expand All @@ -113,12 +119,12 @@ runs:
with:
push-to-fork: ${{ env.FORK }}
token: ${{ inputs.cla_token }}
branch: cla-${{ env.CONTRIBUTOR }}
branch: cla-${{ env.CONTRIBUTOR_ID }}
delete-branch: true
commit-message: 🤖 Add ${{ env.CONTRIBUTOR }} as CLA signee
commit-message: 🤖 Add ${{ env.CONTRIBUTOR_LOGIN }} (${{ env.CONTRIBUTOR_ID }}) as CLA signee
author: Conda Bot <[email protected]>
committer: Conda Bot <[email protected]>
title: 🤖 Add ${{ env.CONTRIBUTOR }} as CLA signee
title: 🤖 Add ${{ env.CONTRIBUTOR_LOGIN }} (${{ env.CONTRIBUTOR_ID }}) as CLA signee
body: Xref ${{ github.event.html_url }}

# if unsigned, create sticky comment
Expand All @@ -140,7 +146,7 @@ runs:
We require contributors to sign our [Contributor License Agreement][cla] and we don't
have one on file for @${{ env.CONTRIBUTOR }}.
have one on file for @${{ env.CONTRIBUTOR_LOGIN }} (${{ env.CONTRIBUTOR_ID }}).
In order for us to review and merge your code, please e-sign the
Expand Down

0 comments on commit 6264ecd

Please sign in to comment.