Skip to content

Commit

Permalink
Update check-cla to customize which CLA repo
Browse files Browse the repository at this point in the history
  • Loading branch information
kenodegard committed Apr 4, 2023
1 parent 3b8905c commit 6facc7a
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions check-cla/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,31 @@ inputs:
token:
description: Token for commenting and labeling on contributor's PR
required: true
infrastructure_token:
description: Token for opening singee PR in conda/infrastructure
required: true
label:
description: Label to apply to contributor's PR once CLA is singed
required: true
cla_repo:
description: Upstream repository in which to create PR
default: conda/infrastructure
cla_fork:
description: Fork of cla_repo in which to create branch
default: conda-bot/infrastructure
cla_token:
description: Token for opening singee PR in the provided `cla_repo`
required: true
cla_path:
description: Path to the CLA signees file within the provided `cla_repo`
default: .clabot

runs:
using: composite
steps:
# sha, labels, hasLabel
- name: Get PR metadata
id: pr
uses: actions/github-script@v6
with:
github-token: ${{ inputs.token }}
script: |
const { owner, repo, number } = context.issue;
const pullRequest = await github.rest.pulls.get({
Expand All @@ -27,6 +38,7 @@ runs:
pull_number: number,
});
console.log(pullRequest);
const sha = pullRequest.data.head.sha;
console.log(sha);
core.setOutput('sha', sha);
Expand All @@ -48,20 +60,21 @@ runs:
state: pending
sha: ${{ steps.pr.outputs.sha || github.sha }}

# contributors, hasSigned
- name: Check if current actor has signed
uses: actions/github-script@v6
id: contributors
with:
github-token: ${{ inputs.token }}
script: |
console.log(context);
const [owner, repo] = '${{ inputs.cla_repo }}'.split("/", 1);
const getContributors = async () => {
try {
const results = (
await github.rest.repos.getContent({
owner: 'conda',
repo: 'infrastructure',
path: '.clabot'
owner: owner,
repo: repo,
path: '${{ inputs.cla_path }}'
})
);
return JSON.parse(Buffer.from(results.data.content, results.data.encoding).toString('utf-8')).contributors;
Expand All @@ -72,12 +85,14 @@ runs:
}
const contributors = await getContributors();
console.log(contributors);
core.setOutput('contributors', contributors);
const pull_request = (context.payload.issue || context.payload.pull_request || context.payload);
const creator = pull_request.user.login;
console.log(creator);
const hasSigned = contributors.includes(creator);
console.log(hasSigned);
core.setOutput('contributors', contributors);
core.setOutput('hasSigned', hasSigned);
# add cla-signed label if actor has already signed
Expand Down Expand Up @@ -106,31 +121,32 @@ runs:
name: '${{ inputs.label }}'
})
# checkout conda/infrastructure to update .clabot
# checkout cla_repo to update cla_path
- uses: actions/checkout@v3
if: steps.contributors.outputs.hasSigned == 'false'
with:
repository: conda/infrastructure
repository: ${{ inputs.cla_repo }}

# update .clabot
# update cla_path
- shell: python
if: steps.contributors.outputs.hasSigned == 'false'
run: |
import json
from pathlib import Path
path = Path(".clabot")
clabot = json.loads(path.read_text())
clabot["contributors"].append("${{ github.actor }}")
clabot["contributors"].sort()
path.write_text(json.dumps(clabot))
path = Path("${{ inputs.cla_path }}")
signees = json.loads(path.read_text())
signees["contributors"].append("${{ github.actor }}")
signees["contributors"].sort()
path.write_text(json.dumps(signees))
# create PR
- uses: peter-evans/create-pull-request@v4
id: cla-pr
if: steps.contributors.outputs.hasSigned == 'false'
with:
token: ${{ inputs.infrastructure_token }}
push-to-fork: ${{ inputs.cla_fork }}
token: ${{ inputs.cla_token }}
branch: cla-${{ github.actor }}
commit-message: Adding CLA singee ${{ github.actor }}
title: Adding CLA singee ${{ github.actor }}
Expand Down

0 comments on commit 6facc7a

Please sign in to comment.