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

Check for existence of backport branch before trying to create it #125

Merged
merged 1 commit into from
Apr 9, 2024

Conversation

yardenshoham
Copy link
Collaborator

Let's try it

Signed-off-by: Yarden Shoham <git@yardenshoham.com>
@silverwind
Copy link
Collaborator

silverwind commented Apr 3, 2024

Do we read the backport/done label elsewhere which could be removed with this? Setting it is fine, but just not reading it to determine done status.

@yardenshoham
Copy link
Collaborator Author

`is:pr is:merged base:main label:backport/v${giteaMajorMinorVersion} -label:backport/done -label:backport/manual repo:go-gitea/gitea`,

@silverwind
Copy link
Collaborator

Hmm I think we may have to remove the -label:backport/done filter. Imagine a scenario:

  • PR with two backport tags merges
  • Bot creates first backport, sets backport/done, bot stops for whatever reason
  • Bot runs again does not see that one backport is still outstanding on the PR because of that filter

So the mechanism will work as long as the bot does both backports in the same run, but that likely can not be guaranteed, right?

@silverwind
Copy link
Collaborator

I guess above could be fixed if backport/done is only set only after all backports were done. Did not check the code in detail yet.

@yardenshoham
Copy link
Collaborator Author

The bot never sets a backport/done when there is more than 1 backport/v* label

@yardenshoham
Copy link
Collaborator Author

// if the original PR had exactly one backport/* label, add the backport/done label to it
const backportLabels = originalPr.labels
.filter((label) => label.name.startsWith("backport/"));
if (backportLabels.length === 1) {
await addLabels(originalPr.number, ["backport/done"]);
console.log(`Added backport/done label to PR #${originalPr.number}`);
}
};

@silverwind
Copy link
Collaborator

silverwind commented Apr 3, 2024

// if the original PR had exactly one backport/* label, add the backport/done label to it
const backportLabels = originalPr.labels
.filter((label) => label.name.startsWith("backport/"));
if (backportLabels.length === 1) {
await addLabels(originalPr.number, ["backport/done"]);
console.log(`Added backport/done label to PR #${originalPr.number}`);
}
};

Hmm I think that is the problem, it should have set backport/done after is has completed all backport PRs. I think we have to move the label setting out of createBackportPr and into the main run function. Then once, the run has completed, verify that all backport PRs exist and if so, set backport/done. That should at least fix the issue seen at go-gitea/gitea#30245.

@yardenshoham
Copy link
Collaborator Author

I could give it a shot next week

@silverwind
Copy link
Collaborator

I think my suggestion with the branch was bad because a backport is only truly done once the PR exists, the branch creation is just one of the steps.

@yardenshoham
Copy link
Collaborator Author

That's the same thing anyway, we only push if the cherry-pick succeeds

@silverwind
Copy link
Collaborator

silverwind commented Apr 3, 2024

Here's a pseudo-code how I would do it:

- fetch candidates, excluding done label
- const todo = Set([`${prnum}-${branch}`],...)
- for each candidate
  - check if branch exists, if not, create it
  - check if pr exists, if not, create it
  - todo.delete(`${prnum}-${branch}`) # at this point we know a pr is done
- if (todo.size === 0) setLabel(`backport/done`)

@silverwind
Copy link
Collaborator

silverwind commented Apr 3, 2024

Only question is whether GH API can help with "check if pr exists", e.g. determine PR number from branch name alone, likely there must be some way.

@yardenshoham yardenshoham merged commit 6602158 into main Apr 9, 2024
2 checks passed
@yardenshoham yardenshoham deleted the issues/124 branch April 9, 2024 15:38
@silverwind
Copy link
Collaborator

I don't think this fix was right and it shouldn't have merged imho.

@yardenshoham
Copy link
Collaborator Author

This fix is correct but causes too many API calls, which leads to rate limiting. The easiest solution I can think of is memorization of the backportPrExists function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants