Add script for generating backports of PRs#9281
Conversation
|
I'm marking it as draft until I allocate some time to improve this, probably next week. Some context:
|
37ae0bf to
1abdc5b
Compare
1abdc5b to
6c3d859
Compare
|
Now I'm happier with the current solution. Regarding the last set of problems:
On the last week or so there was a big refactor of this file (#9231), so I only keep consistency for how the script is called.
Moved it to Decidim::GithubManager::Querier and applied it to changelog_generator
This is still in the script invocation as I'm not fully convinced if this is a good idea. I think the invocation will be cleaner, you'd not leave secrets in your shell history, and this should be configured only one time, but I'd like to hear another opinion about this.
I've done it already by creating a new repository and mocking up the external calls.
I think this should be fixed as we're not using curl and backticks for this anymore, but I'm not 100% sure as I didin't found any backport with these kind of characters in the last set of PRs to backports. It shouldn't be difficult to fix.
This is solved already, we're using Faraday instead of gh/curl. Related to dependencies, we could probably use https://github.com/ruby-git/ruby-git instead of system's git, but I prefer to not add a new gem dependency for this, and git's CLI should be available in the maintainers local machine. This is ready to be reviewed @ahukkanen |
2211c98 to
6c3d859
Compare
Yep this was also something I was thinking when I tried the change log generator before. I'd pass it through ENV vars but I think for the time being we can live with that. You can also prevent the command being saved to the local history by adding a single space before the command you run. But this is of course up to the users and users make mistakes.
I've read through the code and everything seems fine for me but I'll also test this in actual use later, after which I'll give my actual review.
There are such PRs like #9330 which have the single quote character in their titles. But I'm not sure if there's any better way to handle this because if we changed it to double quotes or backticks, there could be also titles that have those characters in them. In CSV quotation marks are escaped with doubling the quotes contained in the string but because the titles are meant to be read by humans, I would say we can live with that. |
This is in the help text: Line 23 in 8ddf57a Copied from the bin/changelog_generator: decidim/bin/changelog_generator Line 19 in bbe6722 I already had it configured for that, so I didn't remember to add it in the PR description. Sorry. Having the screenshot is much easier to see, maybe adding it at https://docs.decidim.org/en/develop/releases#_producing_the_changelog_md? Or we could start a new section in the docs ( |
Oh sorry I missed that since I just followed the instructions in the PR (when I didn't see that help message). Men don't need any instructions with technical stuff/construction projects, right? 🤷♂️ |
ahukkanen
left a comment
There was a problem hiding this comment.
Great work @andreslucena ! I tried this yesterday as you probably noticed already and it worked great after some hickups got it working fine.
Below are few things I noticed with the script when trying it out myself. The main problem was that I have the Decidim repository configured at the upstream remote, not origin as the script assumes.
Another thing to think about is do we want to allow usage of this script to also people who do not have access to commit to the main repository but only to their own fork? They might also benefit from this script in some occasions, even if the default is that we handle the backports at the maintenance team.
One comment regarding that as well below.
These are more of discussion points, so if you feel these are irrelevant, feel free to discard my review.
Suggestion from code review Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>
84ffbe4 to
00ef759
Compare
|
@andreslucena Let me know when this is ready for re-review. |
|
I wanted to try it out once more before sending it back to you, and I've just done that Thurrsday, so It's ready to be reviewed again @ahukkanen. The main change to what you've seen before is that I migrated to Thor as I was arriving to the place where ARGV comes painful. I tried to give it a spin to the use case that you were proposing, but I don't see it clear, so let's merge this as it's now. Then you can propose whatever improvement on the use cases/feature set that you feel in another PR |
Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>
Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>
Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>
Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>
3eff775 to
d533045
Compare
It looks like I didn't catch that as I'm using the GH extension Refined GitHub. I've applied and checked locally your fix. I preferred the ruby version, as shell scripting is more difficult to maintain and understand. This will be applied to the next set of PRs, the current one had still this bug. Now it's ready to be reviewed again. Of course, the best way would be to try this with another set of PRs to fix, or if you prefer, you can close one of the current open backports PR and rerun it against that PR/branch. In that case, you'll also need to delete the remote branch too. |
I'm not sure if you created all the backports with the latest version but there was still duplicate IDs in the commit message titles: That said, I have just tried this locally with #9553 and looking at that PR, the commit history looks correct without the original PR ID: Also when opening the merging section in that PR, I see the commit message title being generated correctly: So as far as the feature itself goes, this seems to be fixed in the backported script itself. In case this still keeps happening in the future, the problem is probably elsewhere and we need to revisit this then with further invetigation. |
ahukkanen
left a comment
There was a problem hiding this comment.
Great work! 👍
Now it seems to work perfectly and I've tested it locally also after the latest changes.
Yes, that's expected. That's what I meant with
I thought I made that the other day, but I was wrong. Sorry about that |
* Add script for generating backports of PRs * Fix linter offenses * Move Github query logic to its own class * Move Git backport logic to its own class * Move Github post logic to its own class * Refactor the backporter script to use the new classes * Use the GH::Querier at the changelog_generator * Use FileUtils.rm_rf instead of rm backticks * Configure local git user for spec * Improve readability in spec * Fix linter offenses * Add safeguard when backporting and the branch already exists * Refactor sha_commit_to_backport method to one line * Give error when the 'public_repo' scope isn't enabled Suggestion from code review Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi> * Extract backporter class to its own file * Migrate backporter CLI to Thor * Add :exit_with_unstaged_changes option It can be called like this: [--exit-with-unstaged-changes], [--no-exit-with-unstaged-changes] It's optional. It controls whether the script should exit with an error if there are unstaged changes in the current project. Default: true * Move :github_token option to a HEREDOC * Fix namespace in Backporter call * Remove hardcoded `origin` remote Extract it from git. Suggestion from code review. * Exit if there's a problem checking out `develop` Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi> * Check if SHA commit is found Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi> * Check if PR is found in GitHub Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi> * Check if the metadata was returned Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi> * Improve error messages formating * Add documentation * Add support to multiple versions at the same time * Explicitly add active_support dependency * Add clean commit message method to remove original PR ID Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>





🎩 What? Why?
This PR adds the script that I've working on to generate the last set of backports. I'm still not 100% happy with it, but at the moment it's good enough to be validated.
Testing
bin/backporter --github-token=GITHUB_TOKEN --pull-request-id=PULL_REQUEST_ID --version-number=VERSION_NUMBERDocumentation