Skip to content

Instantly share code, notes, and snippets.

@ekohl
Created October 13, 2021 12:57
Show Gist options
  • Save ekohl/9fb9a2b6918f903522ff4ed0bc49bf52 to your computer and use it in GitHub Desktop.
Save ekohl/9fb9a2b6918f903522ff4ed0bc49bf52 to your computer and use it in GitHub Desktop.
Foreman Cherry Pick tool
#!/usr/bin/python3
from argparse import ArgumentParser
from collections import defaultdict
from itertools import chain
from redminelib import Redmine
def get_picks(project_id, query_id):
redmine = Redmine('https://projects.theforeman.org')
issues = redmine.issue.filter(project_id=project_id, query_id=query_id)
picks = defaultdict(dict)
for issue in issues:
if issue.status.name == 'Closed':
picks[issue.project.name][issue] = issue.changesets
return picks
def main():
parser = ArgumentParser()
parser.add_argument('project_id', help='Redmine project ID')
parser.add_argument('query_id', help='Redmine search Query ID', type=int)
parsed = parser.parse_args()
picks = get_picks(parsed.project_id, parsed.query_id)
for project, issues in picks.items():
print(project)
for issue, changesets in issues.items():
print(f'# #{issue.id} {issue} {issue.url}')
if changesets:
print(f'# {" ".join(c["revision"] for c in changesets)}')
else:
print('# No revisions!')
all_changesets = sorted(chain(*issues.values()), key=lambda c: c['committed_on'])
print(f'git cherry-pick -x {" ".join(c["revision"] for c in all_changesets)}')
print()
if __name__ == '__main__':
main()
@ekohl
Copy link
Author

ekohl commented Oct 13, 2021

Example output:

./pick foreman 165
Foreman
# #33621 Remove experimental host wizard page https://projects.theforeman.org/issues/33621
# 91bd681276b7af98fb7f65dffae6dc2fbd8cef00
# #33617 "All audits" link in host details page doesn't work https://projects.theforeman.org/issues/33617
# e8caad7f39b37abcb7486d76c1daa72c1a8a072a
# #33491 Experimental host page kebab menu buttons do nothing https://projects.theforeman.org/issues/33491
# 0a669c0f0e556787e47107f869190b7bac0af5a2
# #33490 Edit button in experimental host page doesn't work https://projects.theforeman.org/issues/33490
# d49fdfeed6bf224eec92f159deb8bad4c51b6846
git cherry-pick -x d49fdfeed6bf224eec92f159deb8bad4c51b6846 91bd681276b7af98fb7f65dffae6dc2fbd8cef00 e8caad7f39b37abcb7486d76c1daa72c1a8a072a 0a669c0f0e556787e47107f869190b7bac0af5a2

Installer
# #33577 Foreman Puppet plugin is enabled in the migration even if Foreman is disabled https://projects.theforeman.org/issues/33577
# ce89a30b315e729a45101a8707fcf88f9e9a39c8
git cherry-pick -x ce89a30b315e729a45101a8707fcf88f9e9a39c8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment