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

fix(core-library): do not create pr when a pr already exists for a ref #66

Merged
merged 6 commits into from Aug 6, 2020

Conversation

TomKristie
Copy link
Contributor

@TomKristie TomKristie commented Aug 5, 2020

Recall that GitHub PRs just point to a reference head which are applied on-top of some base reference head, typically master, and so when the reference gets updated the PR automatically gets updated as well.

There may be scenarios where a pull request is already created for a ref, and a user will re-invoke code-suggester create pr using the same ref. If the force flag/parameter is true, a new ref is not created. Instead code-suggester create pr will force-update the existing reference. If we try to re-create the a pr for the same reference, there will be a duplication issue. Hence, if there is an existing pr, just update the ref, and GitHub will just adjust UI display accordingly to the reference HEAD data. However, if force flag/parameter is false, code-suggester create pr will fail when trying to create the reference because there is a duplicate reference.

TL;DR
When there is an existing pr for the a reference and code-suggester create pr is re-invoked, do not create a new pr. Instead, re-use the old one and update the ref.

Closes #17

@TomKristie TomKristie requested review from chingor13, azizsonawalla and a team August 5, 2020 21:46
@TomKristie TomKristie requested a review from a team as a code owner August 5, 2020 21:46
@codecov
Copy link

codecov bot commented Aug 5, 2020

Codecov Report

Merging #66 into master will increase coverage by 0.15%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #66      +/-   ##
==========================================
+ Coverage   85.96%   86.11%   +0.15%     
==========================================
  Files          14       14              
  Lines        1190     1203      +13     
  Branches       83       81       -2     
==========================================
+ Hits         1023     1036      +13     
  Misses        166      166              
  Partials        1        1              
Impacted Files Coverage Δ
src/github-handler/fork-handler.ts 98.03% <ø> (-0.04%) ⬇️
src/github-handler/pull-request-handler.ts 100.00% <100.00%> (ø)

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 82430a9...1a1ac09. Read the comment docs.

Copy link
Contributor

@chingor13 chingor13 left a comment

Choose a reason for hiding this comment

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

So this handles the case when essentially there is an existing branch. Is this not the same case as the force option?

test/pr.ts Outdated Show resolved Hide resolved
@TomKristie
Copy link
Contributor Author

TomKristie commented Aug 6, 2020

So this handles the case when essentially there is an existing branch. Is this not the same case as the force option?

Correct. Basically if there is an existing PR for the branch, do not create a new PR, re-use the old one. GitHub PRs just point to a reference head which are applied on-top of some reference head, typically master, and so when the reference gets updated the PR automatically gets updated as well.

test/pr.ts Outdated
});
});

it('Invokes octokit pull create when there are similar refs with pull requests open, but not exact refs: extra number', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can nest describe blocks - many of these tests share the same setup for the case of an already existing PR.

describe('when there are similar refs with pull requests open', async () => {
  beforeEach(() => {
    // set up sinon for list pull request
  });
  it('should create another pull request if it's not the exact ref', async () => {

  });
});

'./fixtures/list-pulls-response.json'
);
afterEach(() => {
sandbox.restore();
Copy link
Contributor

@chingor13 chingor13 Aug 6, 2020

Choose a reason for hiding this comment

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

This should be already handled by the outer describe blocks's afterEach which is restoring the sandbox.

@chingor13 chingor13 changed the title feat(core-library): do not create pr when a pr already exists for a ref fix(core-library): do not create pr when a pr already exists for a ref Aug 6, 2020
@TomKristie TomKristie added the automerge Merge the pull request once unit tests and other checks pass. label Aug 6, 2020
@gcf-merge-on-green gcf-merge-on-green bot merged commit 4c7b259 into googleapis:master Aug 6, 2020
@TomKristie TomKristie deleted the re-use-old-prs branch August 6, 2020 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge the pull request once unit tests and other checks pass.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Framework-core: handle existing PRs and existing branches
2 participants