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(platform): update pr baseBranch #20811

Conversation

RahulGautamSingh
Copy link
Collaborator

@RahulGautamSingh RahulGautamSingh commented Mar 8, 2023

Changes

  • update the destination/target branch of existing prs when the basebranch is updated

Context

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please select one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

@RahulGautamSingh
Copy link
Collaborator Author

Missing the code-changes for AWS CodeCommit.

@setchy
Copy link
Collaborator

setchy commented Mar 8, 2023

Nice one @RahulGautamSingh 👏

@RahulGautamSingh
Copy link
Collaborator Author

RahulGautamSingh commented Mar 8, 2023

There seems to be a problem.
The existingPRs won't get updated as baseBranch change doesn't come under title/body update so current ensurePr logic doesn't detect a change & skips the pr update. :)

if (
existingPrTitle === newPrTitle &&
existingPrBodyHash === newPrBodyHash
) {

For this we will need to comapre the PR's target branch with the current base branch

Below are the 2 approaches I could think of:

  1. Use cached baseBranch (not reliable as baseBranch might change sometimes in cache while PR isn't uppdated)
  2. Use existing pr's targetBranch

I tried (2) but into an issue that the targetBranch (base.ref in case of github) isn't being fecthed. Do we need some code-change to get the target-branch when we fetch PR information using API?

@RahulGautamSingh
Copy link
Collaborator Author

Example PR info , github:

I got this as PR info from Github

{
  bodyStruct: {
    debugData: {
      createdInVer: '0.0.0-semantic-release',
      updatedInVer: '0.0.0-semantic-release'
    },
    hash: '596ef3415e2fa328b1473fe2f0fb633e63c39de8ba4db8810df72526adfb735e',
    rebaseRequested: false
  },
  createdAt: '2023-03-08T20:28:33Z',
  labels: [],
  node_id: 'PR_kwDOJGaIwM5Lmnld',
  number: 13,
  reviewers: [],
  sha: '23f17c06d283f7eeccf96851f7ab9b015950b0f1',
  sourceBranch: 'renovate/react-18.x',
  sourceRepo: 'RahulGautamSingh-testing/normalRepo',
  state: 'open',
  title: 'Update dependency react to v18',
  updated_at: '2023-03-08T20:28:33Z'
}

@rarkins
Copy link
Collaborator

rarkins commented Mar 9, 2023

"targetBranch" is an optional field in the Pr interface:

targetBranch?: string;

@RahulGautamSingh
Copy link
Collaborator Author

RahulGautamSingh commented Mar 9, 2023

targetBranch needs to added in the return object here.

export function coerceRestPr(pr: GhRestPr): GhPr {
const bodyStruct = pr.bodyStruct ?? getPrBodyStruct(pr.body);
const result: GhPr = {
number: pr.number,
sourceBranch: pr.head?.ref,
title: pr.title,
state:
pr.state === 'closed' && is.string(pr.merged_at) ? 'merged' : pr.state,
bodyStruct,
updated_at: pr.updated_at,
node_id: pr.node_id,
};

Adding for github for now for testing and will do the same for other platforms if found missing.

@RahulGautamSingh
Copy link
Collaborator Author

RahulGautamSingh commented Mar 9, 2023

This check will create issue for us when trying to update the targetBranch of a PR.

if (
branchIsModified ||
(branchPr.targetBranch &&
branchPr.targetBranch !== branchConfig.baseBranch)
) {

Issue explanation:
When we update baseBranches in renovate-config the BranchConfig for all branches will have updated baseBranch but the targetBranch for existing PRs will be the older ones, thus they will differ and we will stop processing the PR.

Basically there are 2 cases:

  1. baseBranch is updated -> ie. we need to update the pr targetBranch
  2. user updates targetBranch manually -> ie. we mark the pr as edited

We need to handle the 2 cases differently by updating the if-check.

@rarkins
Copy link
Collaborator

rarkins commented Mar 10, 2023

Yes, the question is can we tell the difference between:

  • Unchanged baseBranch, but the user changes target branch and wants us to leave it that way, versus
  • Changed baseBranch, user wants us to change the target branch?

@RahulGautamSingh

This comment was marked as outdated.

@RahulGautamSingh

This comment was marked as outdated.

@RahulGautamSingh

This comment was marked as off-topic.

Copy link
Member

@viceice viceice left a comment

Choose a reason for hiding this comment

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

just remove from review list 😁

@RahulGautamSingh
Copy link
Collaborator Author

Blocked by: #21724

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

update pr upon changing baseBranch
4 participants