Created
October 13, 2021 12:57
-
-
Save ekohl/9fb9a2b6918f903522ff4ed0bc49bf52 to your computer and use it in GitHub Desktop.
Foreman Cherry Pick tool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output: