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

feat: support adding labels to PRs #173

Merged
merged 9 commits into from Feb 25, 2021
Merged

Conversation

noahdietz
Copy link
Contributor

Adds support for adding labels to pull requests.

Fixes #172

@noahdietz noahdietz requested a review from a team February 23, 2021 00:52
@noahdietz noahdietz requested a review from a team as a code owner February 23, 2021 00:52
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Feb 23, 2021
@noahdietz noahdietz changed the title Add labels feat: support adding labels to PRs Feb 23, 2021
@codecov
Copy link

codecov bot commented Feb 23, 2021

Codecov Report

Merging #173 (6800502) into master (8ff45d8) will increase coverage by 0.11%.
The diff coverage is 90.27%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #173      +/-   ##
==========================================
+ Coverage   87.98%   88.09%   +0.11%     
==========================================
  Files          23       24       +1     
  Lines        2222     2294      +72     
  Branches      170      173       +3     
==========================================
+ Hits         1955     2021      +66     
- Misses        266      272       +6     
  Partials        1        1              
Impacted Files Coverage Δ
src/bin/code-suggester.ts 0.00% <0.00%> (ø)
src/github-handler/index.ts 95.00% <0.00%> (+0.26%) ⬆️
src/bin/workflow.ts 81.25% <100.00%> (+0.19%) ⬆️
src/github-handler/issue-handler.ts 100.00% <100.00%> (ø)
src/index.ts 99.56% <100.00%> (+0.01%) ⬆️
src/types/index.ts 98.28% <100.00%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8ff45d8...c60d5f1. Read the comment docs.

@noahdietz
Copy link
Contributor Author

What is a good way to cover the lines added to src/index.ts? I don't see tests for that method.

@bcoe
Copy link
Contributor

bcoe commented Feb 24, 2021

What is a good way to cover the lines added to src/index.ts? I don't see tests for that method.

@noahdietz, for your issue test why don't you do this:

import {addLabels} from '../src';

This will pull in your helper from the index.ts file and should get the coverage up to 100%.

Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

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

This implementation looks really solid to me.

What's your specific use case out of curiosity?

@noahdietz
Copy link
Contributor Author

@noahdietz, for your issue test why don't you do this:

import {addLabels} from '../src';

This will pull in your helper from the index.ts file and should get the coverage up to 100%.

index.ts doesn't export the addLabels function though - so this doesn't compile?

Also, I think one coverage issue is that the call to addLabels is behind a check (options.labels && options.labels.length > 0), that never gets exercised. I was thinking of moving that check into addLabels, so it just returns empty list if there are no labels to set, and the createPullRequest call site unconditionally calls it, making the line covered(?) and I can write a test for the addLabels no-op logic. WDYT?

What's your specific use case out of curiosity?

The gapic-showcase project has some code regeneration steps that run on PRs (to verify that, for example, a proto change results in compilable regenerated code, then runs tests with that newly generated code). I'm using code-suggester to open PRs with those generated changes when the original PR is merged, and I want to add the automerge label to the generated PR :) See here.

issue_number: number,
labels?: string[]
): Promise<string[]> {
if (!labels || labels.length === 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bcoe moved the check on labels into addLabels instead of around the call site.

Comment on lines +70 to +84
it('No-op undefined labels', async () => {
// setup
const stub = sandbox.stub(octokit.issues, 'addLabels').resolves();
// tests
const resultingLabels = await addLabels(
octokit,
upstream,
origin,
issue_number
);
sandbox.assert.neverCalledWith(stub, sinon.match.any);
expect(resultingLabels).to.deep.equal([]);
});

it('No-op with empty labels', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bcoe added no-op tests.

@@ -116,6 +118,20 @@ describe('Make PR main function', () => {
expect(testMaintainersCanModify).equals(maintainersCanModify);
expect(testPrimary).equals(primary);
},
addLabels: (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bcoe Added stub helpers for what actually seems to be the main tests for createPullRequest.

@noahdietz
Copy link
Contributor Author

noahdietz commented Feb 24, 2021

Thanks for your review @bcoe! I tweaked things a bit WRT the no-op case fo addLabels and improved the coverage. LMK if you prefer it the way it was before.

@noahdietz
Copy link
Contributor Author

Thanks guys for the reviews. I can't actually merge this PR so one of you will have to. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to specify labels for a pull request
3 participants