Update check-cla to customize which CLA repo to use - #91
Conversation
check-cla to customize which CLA repo to use
6facc7a to
12b993b
Compare
12b993b to
a21df6e
Compare
a21df6e to
ec9f0b4
Compare
38b19ad to
a3dded4
Compare
eaaa6b1 to
ba5634e
Compare
ba5634e to
83dab52
Compare
1ff2e62 to
3769afa
Compare
30261fa to
9bdcc51
Compare
6121130 to
43ec963
Compare
| # if triggered by a comment, leave a reaction | ||
| - name: Comment Reaction | ||
| uses: peter-evans/create-or-update-comment@v3.0.0 | ||
| if: github.event_name == 'issue_comment' | ||
| with: | ||
| token: ${{ inputs.token }} | ||
| comment-id: ${{ github.event.comment.id }} | ||
| reactions: eyes |
There was a problem hiding this comment.
Leaves a reaction on the @conda-bot check so we know the workflow is running (otherwise theres no indication the bot is working on it)
| # commit status → pending | ||
| - name: Set commit status with pending | ||
| uses: dholth/github-status-action@runs-using-node16 | ||
| uses: conda/actions/set-commit-status@customize-cla-repo | ||
| with: | ||
| authToken: ${{ inputs.token }} | ||
| token: ${{ inputs.token }} | ||
| context: CLA check | ||
| description: Checking conda CLA... | ||
| state: pending | ||
| sha: ${{ steps.pr.outputs.sha || github.sha }} | ||
|
|
There was a problem hiding this comment.
Switch to using our own custom set-commit-status since the third party options are poorly supported or don't do what we want.
a26a461 to
6146699
Compare
| # has_label, number, contributor, url, has_signed | ||
| - name: Collect PR metadata | ||
| uses: actions/github-script@v6 | ||
| id: contributors | ||
| id: metadata | ||
| with: | ||
| github-token: ${{ inputs.token }} | ||
| script: | | ||
| console.log(context); | ||
| const getContributors = async () => { | ||
| try { | ||
| const results = ( | ||
| await github.rest.repos.getContent({ | ||
| owner: 'conda', | ||
| repo: 'infrastructure', | ||
| path: '.clabot' | ||
| }) | ||
| ); | ||
| return JSON.parse(Buffer.from(results.data.content, results.data.encoding).toString('utf-8')).contributors; | ||
| } catch (err) { | ||
| core.error(`Could not retrieve contributors, returning undefined. Reason: ${err}`) | ||
| return undefined; | ||
| } | ||
| } | ||
| const contributors = await getContributors(); | ||
| console.log(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 | ||
| - name: Add label | ||
| const { owner, repo, number } = context.issue; | ||
| core.debug(`owner: ${owner}`); | ||
| core.debug(`repo: ${repo}`); | ||
| core.setOutput('number', number); | ||
| core.debug(`number: ${number}`); | ||
|
|
||
| const raw = await github.rest.pulls.get({ | ||
| owner: owner, | ||
| repo: repo, | ||
| pull_number: number | ||
| }); | ||
| const labels = raw.data.labels.map(label => label.name); | ||
| core.debug(`labels: ${labels}`); | ||
|
|
||
| const has_label = labels.includes('${{ inputs.label }}'); | ||
| core.setOutput('has_label', has_label); | ||
| core.debug(`has_label: ${has_label}`); | ||
|
|
||
| const { content, encoding } = (await github.rest.repos.getContent({ | ||
| owner: owner, | ||
| repo: repo, | ||
| path: '${{ inputs.cla_path }}' | ||
| })).data; | ||
| const contributors = JSON.parse( | ||
| Buffer.from(content, encoding).toString('utf-8') | ||
| ).contributors; | ||
| core.debug(`contributors: ${contributors}`); | ||
|
|
||
| const payload = context.payload.issue || context.payload.pull_request || context.payload; | ||
| const contributor = payload.user.login; | ||
| core.setOutput('contributor', contributor); | ||
| core.debug(`contributor: ${contributor}`); | ||
|
|
||
| const url = payload.html_url; | ||
| core.setOutput('url', url); | ||
| core.debug(`url: ${url}`); | ||
|
|
||
| const has_signed = contributors.includes(contributor); | ||
| core.setOutput('has_signed', has_signed); | ||
| core.debug(`has_signed: ${has_signed}`); |
There was a problem hiding this comment.
Moved sha detection into new set-commit-status action. Removed labels output since we don't use it outside of this scope. Switch hasLabel to has_label for variable consistency.
Flattened logic since the error catching doesn't actually do anything special. Removes contributors output since we don't use it outside of this scope. Switch hasSigned to has_signed for variable naming consistency.
| core.setOutput('hasSigned', hasSigned); | ||
|
|
||
| # add [cla-signed] label if actor has already signed | ||
| - name: Add label |
There was a problem hiding this comment.
Could we add this to a separate javascript file? This is started to get long enough to warrant that, imo.
There was a problem hiding this comment.
Specifying these JS blocks in separate files requires:
steps:
- uses: actions/checkout@v3
- uses: actions/github-script@v6
with:
script: |
const script = require('./path/to/script.js')
await script({github, context, core})
My problem with this is the checkout step which will make it harder to version our actions.
There's an open request for something better: actions/github-script#326
There was a problem hiding this comment.
It's a common pattern for actions to include all JS inlined, even if it's not great, let's follow that for now
| core.setOutput('hasSigned', hasSigned); | ||
|
|
||
| # add [cla-signed] label if actor has already signed | ||
| - name: Add label |
There was a problem hiding this comment.
It's a common pattern for actions to include all JS inlined, even if it's not great, let's follow that for now
| # has_label, number, contributor, url, has_signed | ||
| - name: Collect PR metadata | ||
| uses: actions/github-script@v6 | ||
| id: contributors | ||
| id: metadata | ||
| with: | ||
| github-token: ${{ inputs.token }} | ||
| script: | | ||
| console.log(context); | ||
| const getContributors = async () => { | ||
| try { | ||
| const results = ( | ||
| await github.rest.repos.getContent({ | ||
| owner: 'conda', | ||
| repo: 'infrastructure', | ||
| path: '.clabot' | ||
| }) | ||
| ); | ||
| return JSON.parse(Buffer.from(results.data.content, results.data.encoding).toString('utf-8')).contributors; | ||
| } catch (err) { | ||
| core.error(`Could not retrieve contributors, returning undefined. Reason: ${err}`) | ||
| return undefined; | ||
| } | ||
| } | ||
| const contributors = await getContributors(); | ||
| console.log(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 | ||
| - name: Add label | ||
| const { owner, repo, number } = context.issue; | ||
| core.debug(`owner: ${owner}`); | ||
| core.debug(`repo: ${repo}`); | ||
| core.setOutput('number', number); | ||
| core.debug(`number: ${number}`); | ||
|
|
||
| const raw = await github.rest.pulls.get({ | ||
| owner: owner, | ||
| repo: repo, | ||
| pull_number: number | ||
| }); | ||
| const labels = raw.data.labels.map(label => label.name); | ||
| core.debug(`labels: ${labels}`); | ||
|
|
||
| const has_label = labels.includes('${{ inputs.label }}'); | ||
| core.setOutput('has_label', has_label); | ||
| core.debug(`has_label: ${has_label}`); | ||
|
|
||
| const { content, encoding } = (await github.rest.repos.getContent({ | ||
| owner: owner, | ||
| repo: repo, | ||
| path: '${{ inputs.cla_path }}' | ||
| })).data; | ||
| const contributors = JSON.parse( | ||
| Buffer.from(content, encoding).toString('utf-8') | ||
| ).contributors; | ||
| core.debug(`contributors: ${contributors}`); | ||
|
|
||
| const payload = context.payload.issue || context.payload.pull_request || context.payload; | ||
| const contributor = payload.user.login; | ||
| core.setOutput('contributor', contributor); | ||
| core.debug(`contributor: ${contributor}`); | ||
|
|
||
| const url = payload.html_url; | ||
| core.setOutput('url', url); | ||
| core.debug(`url: ${url}`); | ||
|
|
||
| const has_signed = contributors.includes(contributor); | ||
| core.setOutput('has_signed', has_signed); | ||
| core.debug(`has_signed: ${has_signed}`); |
| @@ -0,0 +1,51 @@ | |||
| --- | |||
| name: Set Commit Status | |||
| description: Modifies the commit status of the most recent commit. | |||
| message: >- | ||
| [cla]: https://conda.io/en/latest/contributing.html#conda-contributor-license-agreement | ||
|
|
||
|
|
||
| We require contributors to sign our [Contributor License Agreement][cla] and we don't | ||
| have one on file for @${{ steps.metadata.outputs.contributor }}. | ||
|
|
||
|
|
||
| In order for us to review and merge your code, please e-sign the [Contributor License Agreement PDF](https://conda.io/en/latest/contributing.html#conda-contributor-license-agreement). We then need to manually verify your signature, merge the PR (${{ steps.cla-pr.outputs.pull-request-url }}), and ping the bot to refresh the PR. | ||
| In order for us to review and merge your code, please e-sign the | ||
| [Contributor License Agreement PDF][cla]. We then need to manually verify your | ||
| signature, merge the PR (${{ steps.pull.outputs.pull-request-url }}), and ping the bot | ||
| to refresh the PR. |
There was a problem hiding this comment.
@kathatherine this is the updated missing CLA message, is this good enough in light of conda/conda-docs#854
To see an example of this in action see conda-sandbox/test-check-cla#45
There was a problem hiding this comment.
Hopefully the PR link will help with anyone who just reads to the CLA signing link and stops (like what happened with some of the PyCon sprinters I was working with). Maybe two links will encourage finishing the paragraph. :P This works for me.
Description
It is difficult to test the
check-claaction since it's hardcoded with a specific repo to find the.clabotfile. This updates the workflow to allow most of the hardcoded values to be customized.Adds a new action
set-commit-statusto replace the unsupported https://github.com/Sibz/github-status-action (similar actions don't work for us, e.g., https://github.com/ouzi-dev/commit-status-updater).See this in action here: https://github.com/conda-sandbox/test-check-cla
Xref #76