-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
cli.py
142 lines (114 loc) · 4.89 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import pathlib
import click
from ..utils.cli import validate_arrow_sources
from .core import IssueTracker, Release
@click.group('release')
@click.option("--src", metavar="<arrow_src>", default=None,
callback=validate_arrow_sources,
help="Specify Arrow source directory.")
@click.option('--github-token', '-t', default=None,
envvar="CROSSBOW_GITHUB_TOKEN",
help='OAuth token for GitHub authentication')
@click.pass_obj
def release(obj, src, github_token):
"""Release releated commands."""
obj['issue_tracker'] = IssueTracker(github_token=github_token)
obj['repo'] = src.path
@release.command('curate', help="Lists release related issues.")
@click.argument('version')
@click.option('--minimal/--full', '-m/-f',
help="Only show actionable issues.", default=False)
@click.pass_obj
def release_curate(obj, version, minimal):
"""Release curation."""
release = Release(version, repo=obj['repo'],
issue_tracker=obj['issue_tracker'])
curation = release.curate(minimal)
click.echo(curation.render('console'))
@release.group('changelog')
def release_changelog():
"""Release changelog."""
pass
@release_changelog.command('add')
@click.argument('version')
@click.pass_obj
def release_changelog_add(obj, version):
"""Prepend the changelog with the current release"""
repo, issue_tracker = obj['repo'], obj['issue_tracker']
# just handle the current version
release = Release(version, repo=repo, issue_tracker=issue_tracker)
if release.is_released:
raise ValueError('This version has been already released!')
changelog = release.changelog()
changelog_path = pathlib.Path(repo) / 'CHANGELOG.md'
current_content = changelog_path.read_text()
new_content = changelog.render('markdown') + current_content
changelog_path.write_text(new_content)
click.echo("CHANGELOG.md is updated!")
@release_changelog.command('generate')
@click.argument('version')
@click.argument('output', type=click.File('w', encoding='utf8'), default='-')
@click.pass_obj
def release_changelog_generate(obj, version, output):
"""Generate the changelog of a specific release."""
repo, issue_tracker = obj['repo'], obj['issue_tracker']
# just handle the current version
release = Release(version, repo=repo, issue_tracker=issue_tracker)
changelog = release.changelog()
output.write(changelog.render('markdown'))
@release_changelog.command('regenerate')
@click.pass_obj
def release_changelog_regenerate(obj):
"""Regeneretate the whole CHANGELOG.md file"""
issue_tracker, repo = obj['issue_tracker'], obj['repo']
changelogs = []
issue_tracker = IssueTracker(issue_tracker=issue_tracker)
for version in issue_tracker.project_versions():
if not version.released:
continue
release = Release(version, repo=repo,
issue_tracker=issue_tracker)
click.echo('Querying changelog for version: {}'.format(version))
changelogs.append(release.changelog())
click.echo('Rendering new CHANGELOG.md file...')
changelog_path = pathlib.Path(repo) / 'CHANGELOG.md'
with changelog_path.open('w') as fp:
for cl in changelogs:
fp.write(cl.render('markdown'))
@release.command('cherry-pick')
@click.argument('version')
@click.option('--dry-run/--execute', default=True,
help="Display the git commands instead of executing them.")
@click.option('--recreate/--continue', default=True,
help="Recreate the maintenance branch or only apply unapplied "
"patches.")
@click.pass_obj
def release_cherry_pick(obj, version, dry_run, recreate):
"""
Cherry pick commits.
"""
issue_tracker = obj['issue_tracker']
release = Release(version,
repo=obj['repo'], issue_tracker=issue_tracker)
if not dry_run:
release.cherry_pick_commits(recreate_branch=recreate)
else:
click.echo(f'git checkout -b {release.branch} {release.base_branch}')
for commit in release.commits_to_pick():
click.echo('git cherry-pick {}'.format(commit.hexsha))