Apache DataFusion SQL Query Engine
ARROW-2948: [Packaging] Generate changelog with crossbow
Krisztián Szűcs58cefd483fcf
diff --git a/dev/tasks/README.md b/dev/tasks/README.mdindex 666f326494..c5975f59e9 100644--- a/dev/tasks/README.md+++ b/dev/tasks/README.md@@ -97,12 +97,12 @@ submission. The tasks are defined in `tasks.yml`8. Install the python dependencies for the script:```bash- conda install -y jinja2 pygit2 click ruamel.yaml setuptools_scm github3.py python-gnupg+ conda install -y jinja2 pygit2 click ruamel.yaml setuptools_scm github3.py python-gnupg toolz jira``````bash# pygit2 requires libgit2: http://www.pygit2.org/install.html- pip install jinja2 pygit2 click ruamel.yaml setuptools_scm github3.py python-gnupg+ pip install jinja2 pygit2 click ruamel.yaml setuptools_scm github3.py python-gnupg toolz jira```9. Try running it:diff --git a/dev/tasks/crossbow.py b/dev/tasks/crossbow.pyindex fae5c0a43b..324b997ae8 100755--- a/dev/tasks/crossbow.py+++ b/dev/tasks/crossbow.py@@ -17,19 +17,22 @@# specific language governing permissions and limitations# under the License.-import hashlibimport osimport reimport sysimport timeimport click+import hashlib+import gnupg+import toolzimport pygit2import github3-import gnupg+import jira.clientfrom io import StringIOfrom pathlib import Pathfrom textwrap import dedent+from datetime import datetimefrom jinja2 import Template, StrictUndefinedfrom setuptools_scm import get_versionfrom ruamel.yaml import YAML@@ -38,6 +41,107 @@ from ruamel.yaml import YAMLCWD = Path(__file__).parent.absolute()+NEW_FEATURE = 'New Features and Improvements'+BUGFIX = 'Bug Fixes'+++def md(template, *args, **kwargs):+ """Wraps string.format with naive markdown escaping"""+ def escape(s):+ for char in ('*', '#', '_', '~', '`', '>'):+ s = s.replace(char, '\\' + char)+ return s+ return template.format(*map(escape, args), **toolz.valmap(escape, kwargs))+++class JiraChangelog:++ def __init__(self, version, username, password,+ server='https://issues.apache.org/jira'):+ self.server = server+ # clean version to the first numbers+ self.version = '.'.join(version.split('.')[:3])+ query = ("project=ARROW "+ "AND fixVersion='{0}' "+ "AND status = Resolved "+ "AND resolution in (Fixed, Done) "+ "ORDER BY issuetype DESC").format(self.version)+ self.client = jira.client.JIRA({'server': server},+ basic_auth=(username, password))+ self.issues = self.client.search_issues(query, maxResults=9999)++ def format_markdown(self):+ out = StringIO()++ issues_by_type = toolz.groupby(lambda i: i.fields.issuetype.name,+ self.issues)+ for typename, issues in sorted(issues_by_type.items()):+ issues.sort(key=lambda x: x.key)++ out.write(md('## {}\n\n', typename))+ for issue in issues:+ out.write(md('* {} - {}\n', issue.key, issue.fields.summary))+ out.write('\n')++ return out.getvalue()++ def format_website(self):+ # jira category => website category mapping+ categories = {+ 'New Feature': 'feature',+ 'Improvement': 'feature',+ 'Wish': 'feature',+ 'Task': 'feature',+ 'Test': 'bug',+ 'Bug': 'bug',+ 'Sub-task': 'feature'+ }+ titles = {+ 'feature': 'New Features and Improvements',+ 'bugfix': 'Bug Fixes'+ }++ issues_by_category = toolz.groupby(+ lambda issue: categories[issue.fields.issuetype.name],+ self.issues+ )++ out = StringIO()++ for category in ('feature', 'bug'):+ title = titles[category]+ issues = issues_by_category[category]+ issues.sort(key=lambda x: x.key)++ out.write(md('## {}\n\n', title))+ for issue in issues:+ link = md('[{0}]({1}/browse/{0})', issue.key, self.server)+ out.write(md('* {} - {}\n', link, issue.fields.summary))+ out.write('\n')++ return out.getvalue()++ def render(self, old_changelog, website=False):+ old_changelog = old_changelog.splitlines()+ if website:+ new_changelog = self.format_website()+ else:+ new_changelog = self.format_markdown()++ out = StringIO()++ # Apache license header+ out.write('\n'.join(old_changelog[:18]))++ # Newly generated changelog+ today = datetime.today().strftime('%d %B %Y')+ out.write(md('\n\n# Apache Arrow {} ({})\n\n', self.version, today))+ out.write(new_changelog)+ out.write('\n'.join(old_changelog[19:]))++ return out.getvalue().strip()++class GitRemoteCallbacks(pygit2.RemoteCallbacks):def __init__(self, token):@@ -414,6 +518,37 @@ def crossbow(ctx, github_token, arrow_path, queue_path):ctx.obj['queue'] = Queue(Path(queue_path), github_token=github_token)[email protected]('--changelog-path', '-c', type=click.Path(exists=True),+ default=DEFAULT_ARROW_PATH / 'CHANGELOG.md',+ help='Path of changelog to update')[email protected]('--arrow-version', '-v', default=None,+ help='Set target version explicitly')[email protected]('--is-website', '-w', default=False)[email protected]('--jira-username', '-u', default=None, help='JIRA username')[email protected]('--jira-password', '-P', default=None, help='JIRA password')[email protected]('--dry-run/--write', default=False,+ help='Just display the new changelog, don\'t write it')[email protected]_context+def changelog(ctx, changelog_path, arrow_version, is_website, jira_username,+ jira_password, dry_run):+ changelog_path = Path(changelog_path)+ target = Target.from_repo(ctx.obj['arrow'])+ version = arrow_version or target.version++ changelog = JiraChangelog(version, username=jira_username,+ password=jira_password)+ new_content = changelog.render(changelog_path.read_text(),+ website=is_website)++ if dry_run:+ click.echo(new_content)+ else:+ changelog_path.write_text(new_content)+ click.echo('New changelog successfully generated, see git diff for the'+ 'changes')++def load_tasks_from_config(config_path, task_names, group_names):with Path(config_path).open() as fp:config = yaml.load(fp)