Skip to content

Commit

Permalink
Use Github issues instead of redmine
Browse files Browse the repository at this point in the history
[noissue]
  • Loading branch information
fao89 authored and goosemania committed Dec 21, 2021
1 parent 85c3424 commit 7289510
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 178 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.

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


import requests
import os
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_file"
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_file")


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))
)

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.")
gi = repo.get_issue(int(issue))
if gi.pull_request:
sys.exit(f"Error: issue #{issue} is a pull request.")
if gi.closed_at:
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 @@ -320,8 +320,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_file"


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 CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Changelog update
The CHANGES.rst file is managed using the `towncrier tool <https://github.com/hawkowl/towncrier>`_
and all non trivial changes must be accompanied by a news entry.

To add an entry to the news file, you first need an issue in pulp.plan.io describing the change you
To add an entry to the news file, you first need an issue in github describing the change you
want to make. Once you have an issue, take its number and create a file inside of the ``CHANGES/``
directory named after that issue number with an extension of .feature, .bugfix, .doc, .removal, or
.misc. So if your issue is 3543 and it fixes a bug, you would create the file
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Community
This plugin exists to serve the community. If we can do more for your use case, please let us know!
Also, contributions are greatly appreciated in the form of:

1. `Redmine Issues <https://pulp.plan.io/projects/pulp_file/issues>`_
1. `Github Issues <https://github.com/pulp/pulp_file/issues>`_
2. `Github Pull Requests <https://github.com/pulp/pulp_file>`_
3. `Helping other users <https://pulpproject.org/get_involved/>`_

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_file/issues/{issue}>`_"

[tool.black]
line-length = 100
Expand Down
4 changes: 2 additions & 2 deletions template_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ disabled_redis_runners:
docker_fixtures: true
docs_test: true
flake8: true
issue_tracker: redmine
issue_tracker: github
noissue_marker: '[noissue]'
plugin_app_label: file
plugin_camel: PulpFile
Expand Down Expand Up @@ -78,7 +78,7 @@ test_fips_nightly: false
test_performance: true
test_released_plugin_with_next_pulpcore_release: true
test_s3: true
update_redmine: true
update_redmine: false
upgrade_range:
- pulp-certguard_branch: 1.2
pulp_file_branch: 1.6
Expand Down

0 comments on commit 7289510

Please sign in to comment.