Skip to content

Commit

Permalink
Release script = milestone automation
Browse files Browse the repository at this point in the history
[noissue]
  • Loading branch information
fao89 committed Jul 3, 2020
1 parent a1d54e2 commit cd86b0e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 6 deletions.
74 changes: 68 additions & 6 deletions .travis/release.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,66 @@
import argparse
import asyncio
import json
import os
import textwrap
from collections import defaultdict

import aiohttp
from git import Repo


REDMINE_QUERY_URL = "https://pulp.plan.io/issues?set_filter=1&status_id=*&issue_id="
REDMINE_URL = "https://pulp.plan.io"
REDMINE_QUERY_URL = f"{REDMINE_URL}/issues?set_filter=1&status_id=*&issue_id="


async def get_redmine_issue_data(url):
"""Get issue JSON from redmine."""
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
return await response.json()


async def validate_redmine_data(redmine_query_url, redmine_data):
"""Validate redmine milestone."""
done, _ = await asyncio.wait(redmine_data)
issues_data = [i.result() for i in done]
milestone_set = set()
project_set = set()
stats = defaultdict(list)
for issue in issues_data:
issue_id = issue["issue"]["id"]

project_name = issue["issue"]["project"]["name"]
project_set.update([project_name])
stats[f"project_{project_name.lower().replace(' ', '_')}"].append(issue_id)

if issue["issue"]["status"]["name"] != "MODIFIED":
stats["status_not_modified"].append(issue_id)

milestone = issue["issue"].get("fixed_version", {}).get("name")
if not milestone:
stats["without_milestone"].append(issue_id)
else:
milestone_set.update([milestone])
stats[f"milestone_{milestone}"].append(issue_id)

print(f"\n\nRedmine stats: {json.dumps(stats, indent=2)}")
error_messages = []
if stats.get("status_not_modified"):
error_messages.append(f"One or more issues are not MODIFIED {stats['status_not_modified']}")
if stats.get("without_milestone"):
error_messages.append(
f"One or more issues are not associated with a milestone {stats['without_milestone']}"
)
if len(milestone_set) > 1:
error_messages.append(f"Issues with different milestones - {milestone_set}")
if len(project_set) > 1:
error_messages.append(f"Issues with different projects - {project_set}")
if error_messages:
error_messages.append(f"Verify at {redmine_query_url}")
raise RuntimeError("\n".join(error_messages))


release_path = os.path.dirname(os.path.abspath(__file__))
plugin_path = release_path
if ".travis" in release_path:
Expand All @@ -17,11 +72,18 @@
exec(version_line, version)
release_version = version["__version__"].replace(".dev", "")

to_close = []
issues_to_close = []
redmine_issues = []
for filename in os.listdir(f"{plugin_path}/CHANGES"):
if filename.split(".")[0].isdigit():
to_close.append(filename.split(".")[0])
issues = ",".join(to_close)
issue = filename.split(".")[0]
issue_url = f"{REDMINE_URL}/issues/{issue}.json"
redmine_issues.append(get_redmine_issue_data(issue_url))
issues_to_close.append(issue)

issues = ",".join(issues_to_close)
redmine_final_query = f"{REDMINE_QUERY_URL}{issues}"
asyncio.run(validate_redmine_data(redmine_final_query, redmine_issues))

helper = textwrap.dedent(
"""\
Expand Down Expand Up @@ -101,7 +163,7 @@
git.add(f"{plugin_path}/setup.py")
git.add(f"{plugin_path}/requirements.txt")
git.add(f"{plugin_path}/.bumpversion.cfg")
git.commit("-m", f"Releasing {release_version}\n\n[noissue]")
git.commit("-m", f"Releasing {release_version}\n\n{redmine_final_query}\n[noissue]")

sha = repo.head.object.hexsha
short_sha = git.rev_parse(sha, short=7)
Expand Down Expand Up @@ -136,5 +198,5 @@
git.add(f"{plugin_path}/.bumpversion.cfg")
git.commit("-m", f"Bump to {new_dev_version}\n\n[noissue]")

print(f"\n\nRedmine query of issues to close:\n{REDMINE_QUERY_URL}{issues}")
print(f"\n\nRedmine query of issues to close:\n{redmine_final_query}")
print(f"\nRelease commit == {short_sha}")
3 changes: 3 additions & 0 deletions .travis/release_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
aiohttp
bump2version
gitpython

0 comments on commit cd86b0e

Please sign in to comment.