Skip to content

Commit 6facc7a

Browse files
committed
Update check-cla to customize which CLA repo
1 parent 3b8905c commit 6facc7a

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

check-cla/action.yml

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,31 @@ inputs:
55
token:
66
description: Token for commenting and labeling on contributor's PR
77
required: true
8-
infrastructure_token:
9-
description: Token for opening singee PR in conda/infrastructure
10-
required: true
118
label:
129
description: Label to apply to contributor's PR once CLA is singed
1310
required: true
11+
cla_repo:
12+
description: Upstream repository in which to create PR
13+
default: conda/infrastructure
14+
cla_fork:
15+
description: Fork of cla_repo in which to create branch
16+
default: conda-bot/infrastructure
17+
cla_token:
18+
description: Token for opening singee PR in the provided `cla_repo`
19+
required: true
20+
cla_path:
21+
description: Path to the CLA signees file within the provided `cla_repo`
22+
default: .clabot
1423

1524
runs:
1625
using: composite
1726
steps:
27+
# sha, labels, hasLabel
1828
- name: Get PR metadata
1929
id: pr
2030
uses: actions/github-script@v6
2131
with:
32+
github-token: ${{ inputs.token }}
2233
script: |
2334
const { owner, repo, number } = context.issue;
2435
const pullRequest = await github.rest.pulls.get({
@@ -27,6 +38,7 @@ runs:
2738
pull_number: number,
2839
});
2940
console.log(pullRequest);
41+
3042
const sha = pullRequest.data.head.sha;
3143
console.log(sha);
3244
core.setOutput('sha', sha);
@@ -48,20 +60,21 @@ runs:
4860
state: pending
4961
sha: ${{ steps.pr.outputs.sha || github.sha }}
5062

63+
# contributors, hasSigned
5164
- name: Check if current actor has signed
5265
uses: actions/github-script@v6
5366
id: contributors
5467
with:
55-
github-token: ${{ inputs.token }}
5668
script: |
5769
console.log(context);
70+
const [owner, repo] = '${{ inputs.cla_repo }}'.split("/", 1);
5871
const getContributors = async () => {
5972
try {
6073
const results = (
6174
await github.rest.repos.getContent({
62-
owner: 'conda',
63-
repo: 'infrastructure',
64-
path: '.clabot'
75+
owner: owner,
76+
repo: repo,
77+
path: '${{ inputs.cla_path }}'
6578
})
6679
);
6780
return JSON.parse(Buffer.from(results.data.content, results.data.encoding).toString('utf-8')).contributors;
@@ -72,12 +85,14 @@ runs:
7285
}
7386
const contributors = await getContributors();
7487
console.log(contributors);
88+
core.setOutput('contributors', contributors);
89+
7590
const pull_request = (context.payload.issue || context.payload.pull_request || context.payload);
7691
const creator = pull_request.user.login;
7792
console.log(creator);
93+
7894
const hasSigned = contributors.includes(creator);
7995
console.log(hasSigned);
80-
core.setOutput('contributors', contributors);
8196
core.setOutput('hasSigned', hasSigned);
8297
8398
# add cla-signed label if actor has already signed
@@ -106,31 +121,32 @@ runs:
106121
name: '${{ inputs.label }}'
107122
})
108123
109-
# checkout conda/infrastructure to update .clabot
124+
# checkout cla_repo to update cla_path
110125
- uses: actions/checkout@v3
111126
if: steps.contributors.outputs.hasSigned == 'false'
112127
with:
113-
repository: conda/infrastructure
128+
repository: ${{ inputs.cla_repo }}
114129

115-
# update .clabot
130+
# update cla_path
116131
- shell: python
117132
if: steps.contributors.outputs.hasSigned == 'false'
118133
run: |
119134
import json
120135
from pathlib import Path
121136
122-
path = Path(".clabot")
123-
clabot = json.loads(path.read_text())
124-
clabot["contributors"].append("${{ github.actor }}")
125-
clabot["contributors"].sort()
126-
path.write_text(json.dumps(clabot))
137+
path = Path("${{ inputs.cla_path }}")
138+
signees = json.loads(path.read_text())
139+
signees["contributors"].append("${{ github.actor }}")
140+
signees["contributors"].sort()
141+
path.write_text(json.dumps(signees))
127142
128143
# create PR
129144
- uses: peter-evans/create-pull-request@v4
130145
id: cla-pr
131146
if: steps.contributors.outputs.hasSigned == 'false'
132147
with:
133-
token: ${{ inputs.infrastructure_token }}
148+
push-to-fork: ${{ inputs.cla_fork }}
149+
token: ${{ inputs.cla_token }}
134150
branch: cla-${{ github.actor }}
135151
commit-message: Adding CLA singee ${{ github.actor }}
136152
title: Adding CLA singee ${{ github.actor }}

0 commit comments

Comments
 (0)