Skip to content

Commit

Permalink
Use GitHub issues instead of redmine
Browse files Browse the repository at this point in the history
[noissue]

This reverts commit 948dcf6.
  • Loading branch information
quba42 committed Jan 11, 2022
1 parent 3682803 commit 05a8213
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 175 deletions.
35 changes: 0 additions & 35 deletions .ci/scripts/redmine.py

This file was deleted.

26 changes: 0 additions & 26 deletions .ci/scripts/update_redmine.sh

This file was deleted.

32 changes: 13 additions & 19 deletions .ci/scripts/validate_commit_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,32 @@
from pathlib import Path


import requests
import os
import warnings
from github import Github


NO_ISSUE = "[noissue]"
CHANGELOG_EXTS = [".feature", ".bugfix", ".doc", ".removal", ".misc", ".deprecation"]


KEYWORDS = ["fixes", "closes", "re", "ref"]
STATUSES = ["NEW", "ASSIGNED", "POST", "MODIFIED"]
REDMINE_URL = "https://pulp.plan.io"
KEYWORDS = ["fixes", "closes"]

sha = sys.argv[1]
project = "pulp_deb"
message = subprocess.check_output(["git", "log", "--format=%B", "-n 1", sha]).decode("utf-8")
g = Github(os.environ.get("GITHUB_TOKEN"))
repo = g.get_repo("pulp/pulp_deb")


def __check_status(issue):
response = requests.get(f"{REDMINE_URL}/issues/{issue}.json")
response.raise_for_status()
bug_json = response.json()
status = bug_json["issue"]["status"]["name"]
if status not in STATUSES:
sys.exit(
"Error: issue #{issue} has invalid status of {status}. Status must be one of "
"{statuses}.".format(issue=issue, status=status, statuses=", ".join(STATUSES))
gi = repo.get_issue(int(issue))
if gi.pull_request:
sys.exit(f"Error: issue #{issue} is a pull request.")
if gi.closed_at and "cherry picked from commit" not in message:
warnings.warn(
"When backporting, make sure to have 'cherry picked from commit' in the commit message."
)

if project:
project_id = bug_json["issue"]["project"]["id"]
project_json = requests.get(f"{REDMINE_URL}/projects/{project_id}.json").json()
if project_json["project"]["identifier"] != project:
sys.exit(f"Error: issue {issue} is not in the {project} project.")
sys.exit(f"Error: issue #{issue} is closed.")


def __check_changelog(issue):
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,7 @@ jobs:
- name: Publish client to rubygems
run: bash .github/workflows/scripts/publish_client_gem.sh

- name: Update Redmine
run: bash .ci/scripts/update_redmine.sh


- name: Create release on GitHub
run: bash .github/workflows/scripts/create_release_from_tag.sh ${{ github.event.inputs.release }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/scripts/check_commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ set -euv
echo ::group::REQUESTS
pip3 install requests

pip3 install pygithub

echo ::endgroup::

for sha in $(curl -H "Authorization: token $GITHUB_TOKEN" $GITHUB_CONTEXT | jq '.[].sha' | sed 's/"//g')
Expand Down
91 changes: 1 addition & 90 deletions .github/workflows/scripts/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,70 +20,6 @@

from packaging.requirements import Requirement

from collections import defaultdict
from pathlib import Path
from redminelib import Redmine
from redminelib.exceptions import ResourceAttrError, ResourceSetIndexError
import json

REDMINE_API_KEY = os.environ["REDMINE_API_KEY"]
REDMINE_URL = "https://pulp.plan.io"
REDMINE_QUERY_URL = f"{REDMINE_URL}/issues?set_filter=1&status_id=*&issue_id="
REDMINE_PROJECT = "pulp_deb"


def validate_and_update_redmine_data(redmine_query_url, redmine_issues, release_version):
"""Validate redmine milestone."""
error_messages = []
redmine = Redmine("https://pulp.plan.io", key=REDMINE_API_KEY)
redmine_project = redmine.project.get(REDMINE_PROJECT)
if redmine_project is None:
error_messages.append(f"Redmine project {REDMINE_PROJECT} not found.")
try:
milestone = redmine_project.versions.filter(name=release_version)[0]
except ResourceSetIndexError:
error_messages.append(f"Milestone {release_version} not found.")

stats = defaultdict(list)
for issue in redmine_issues:
redmine_issue = redmine.issue.get(int(issue))

project_name = redmine_issue.project.name
stats[f"project_{project_name.lower().replace(' ', '_')}"].append(issue)
if project_name != redmine_project.name:
stats["wrong_project"].append(issue)

status = redmine_issue.status.name
if "CLOSE" not in status and status != "MODIFIED":
stats["status_not_modified"].append(issue)

try:
issue_milestone = redmine_issue.fixed_version
if redmine_issue.fixed_version.id != milestone.id:
stats["wrong_milestone"].append(issue)
stats[f"milestone_{issue_milestone.name}"].append(issue)
except ResourceAttrError:
redmine.issue.update(redmine_issue.id, fixed_version_id=milestone.id)
stats["added_to_milestone"].append(issue)

print(f"\n\nRedmine stats: {json.dumps(stats, indent=2)}")
if stats.get("wrong_project"):
error_messages.append(
f"One or more issues are associated to the wrong project {stats['wrong_project']}"
)
if stats.get("status_not_modified"):
error_messages.append(f"One or more issues are not MODIFIED {stats['status_not_modified']}")
if stats.get("wrong_milestone"):
error_messages.append(
f"One or more issues are associated to the wrong milestone {stats['wrong_milestone']}"
)

if error_messages:
error_messages.append(f"Verify at {redmine_query_url}")
raise RuntimeError("\n".join(error_messages))

return f"{milestone.url}.json"


async def get_package_from_pypi(package_name, plugin_path):
"""
Expand Down Expand Up @@ -120,18 +56,6 @@ async def get_package_from_pypi(package_name, plugin_path):

def create_release_commits(repo, release_version, plugin_path):
"""Build changelog, set version, commit, bump to next dev version, commit."""
issues_to_close = set()
for filename in Path(f"{plugin_path}/CHANGES").rglob("*"):
if filename.stem.isdigit():
issue = filename.stem
issues_to_close.add(issue)

issues = ",".join(issues_to_close)
redmine_final_query = f"{REDMINE_QUERY_URL}{issues}"
milestone_url = validate_and_update_redmine_data(
redmine_final_query, issues_to_close, release_version
)

# First commit: changelog
os.system(f"towncrier --yes --version {release_version}")
git = repo.git
Expand All @@ -148,18 +72,7 @@ def create_release_commits(repo, release_version, plugin_path):
git.add(f"{plugin_path}/requirements.txt")
git.add(f"{plugin_path}/.bumpversion.cfg")

git.commit(
"-m",
"\n".join(
[
f"Release {release_version}",
"",
f"Redmine Query: {redmine_final_query}",
f"Redmine Milestone: {milestone_url}",
"[noissue]",
]
),
)
git.commit("-m", f"Release {release_version}\n\n[noissue]")

sha = repo.head.object.hexsha
short_sha = git.rev_parse(sha, short=7)
Expand All @@ -181,8 +94,6 @@ def create_release_commits(repo, release_version, plugin_path):
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_final_query}")

print(f"Release commit == {short_sha}")
print(f"All changes were committed on branch: release_{release_version}")
return sha
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ filename = "CHANGES.rst"
directory = "CHANGES/"
title_format = "{version} ({project_date})"
template = "CHANGES/.TEMPLATE.rst"
issue_format = "`#{issue} <https://pulp.plan.io/issues/{issue}>`_"
issue_format = "`#{issue} <https://github.com/pulp/pulp_deb/issues/{issue}>`_"

[[tool.towncrier.type]]
directory = "feature"
Expand Down
4 changes: 2 additions & 2 deletions template_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ disabled_redis_runners: []
docker_fixtures: true
docs_test: true
flake8: true
issue_tracker: redmine
issue_tracker: github
noissue_marker: '[noissue]'
plugin_app_label: deb
plugin_camel: PulpDeb
Expand Down Expand Up @@ -67,6 +67,6 @@ test_fips_nightly: false
test_performance: false
test_released_plugin_with_next_pulpcore_release: false
test_s3: true
update_redmine: true
update_redmine: false
upgrade_range: []

0 comments on commit 05a8213

Please sign in to comment.