Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update check-cla to customize which CLA repo to use #91

Merged
merged 30 commits into from
Apr 27, 2023

Conversation

kenodegard
Copy link
Contributor

@kenodegard kenodegard commented Apr 3, 2023

Description

It is difficult to test the check-cla action since it's hardcoded with a specific repo to find the .clabot file. This updates the workflow to allow most of the hardcoded values to be customized.

Adds a new action set-commit-status to 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

@kenodegard kenodegard self-assigned this Apr 3, 2023
@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label Apr 3, 2023
@kenodegard kenodegard changed the title Update check-cla to customize which CLA repo to use Update check-cla to customize which CLA repo to use Apr 3, 2023
@kenodegard kenodegard force-pushed the customize-cla-repo branch 3 times, most recently from 6facc7a to 12b993b Compare April 4, 2023 17:09
@kenodegard kenodegard force-pushed the customize-cla-repo branch 7 times, most recently from eaaa6b1 to ba5634e Compare April 4, 2023 21:36
@kenodegard kenodegard force-pushed the customize-cla-repo branch 4 times, most recently from 1ff2e62 to 3769afa Compare April 4, 2023 22:51
Comment on lines 31 to 38
# if triggered by a comment, leave a reaction
- name: Comment Reaction
uses: peter-evans/[email protected]
if: github.event_name == 'issue_comment'
with:
token: ${{ inputs.token }}
comment-id: ${{ github.event.comment.id }}
reactions: eyes
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

check-cla/action.yml Outdated Show resolved Hide resolved
Comment on lines 63 to 71
# 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 }}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switch to using our own custom set-commit-status since the third party options are poorly supported or don't do what we want.

check-cla/action.yml Outdated Show resolved Hide resolved
Comment on lines +53 to +99
# 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}`);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good changes!

core.setOutput('hasSigned', hasSigned);

# add [cla-signed] label if actor has already signed
- name: Add label

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add this to a separate javascript file? This is started to get long enough to warrant that, imo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a common pattern for actions to include all JS inlined, even if it's not great, let's follow that for now

check-cla/README.md Show resolved Hide resolved
core.setOutput('hasSigned', hasSigned);

# add [cla-signed] label if actor has already signed
- name: Add label
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a common pattern for actions to include all JS inlined, even if it's not great, let's follow that for now

Comment on lines +53 to +99
# 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}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good changes!

@@ -0,0 +1,51 @@
---
name: Set Commit Status
description: Modifies the commit status of the most recent commit.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat!

Comment on lines +165 to +176
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.
Copy link
Contributor Author

@kenodegard kenodegard Apr 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kenodegard kenodegard merged commit b6821f2 into main Apr 27, 2023
@kenodegard kenodegard deleted the customize-cla-repo branch April 27, 2023 19:54
@github-actions github-actions bot added the locked [bot] locked due to inactivity label Apr 27, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed [bot] added once the contributor has signed the CLA locked [bot] locked due to inactivity
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants