diff --git a/.ci/scripts/redmine.py b/.ci/scripts/redmine.py deleted file mode 100755 index 91834b24..00000000 --- a/.ci/scripts/redmine.py +++ /dev/null @@ -1,35 +0,0 @@ -# WARNING: DO NOT EDIT! -# -# This file was generated by plugin_template, and is managed by it. Please use -# './plugin-template --github pulp_file' to update this file. -# -# For more info visit https://github.com/pulp/plugin_template - -import os -import sys - -from redminelib import Redmine - -REDMINE_API_KEY = os.environ["REDMINE_API_KEY"] -REDMINE_QUERY_URL = sys.argv[1] -MILESTONE_URL = sys.argv[2] -RELEASE = sys.argv[3] -CLOSED_CURRENTRELEASE = 11 - -redmine = Redmine(REDMINE_QUERY_URL.split("issues")[0], key=REDMINE_API_KEY) -query_issues = REDMINE_QUERY_URL.split("=")[-1].split(",") -milestone_name = redmine.version.get(MILESTONE_URL.split("/")[-1].split(".")[0]).name -if milestone_name != RELEASE: - raise RuntimeError(f"Milestone name, '{milestone_name}', does not match version, '{RELEASE}'.") - -to_update = [] -for issue in query_issues: - status = redmine.issue.get(int(issue)).status.name - if "CLOSE" not in status and status != "MODIFIED": - raise ValueError("One or more issues are not MODIFIED") - if status == "MODIFIED": # Removing the already closed - to_update.append(int(issue)) - -for issue in to_update: - print(f"Closing #{issue}") - redmine.issue.update(issue, status_id=CLOSED_CURRENTRELEASE) diff --git a/.ci/scripts/update_redmine.sh b/.ci/scripts/update_redmine.sh deleted file mode 100755 index 929a9cc2..00000000 --- a/.ci/scripts/update_redmine.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -# WARNING: DO NOT EDIT! -# -# This file was generated by plugin_template, and is managed by it. Please use -# './plugin-template --github pulp_file' to update this file. -# -# For more info visit https://github.com/pulp/plugin_template - -# make sure this script runs at the repo root -cd "$(dirname "$(realpath -e "$0")")"/../.. - -set -euv - -export COMMIT_MSG=$(git log --format=%B --no-merges -1) -export RELEASE=$(echo $COMMIT_MSG | awk '{print $2}') -export MILESTONE_URL=$(echo $COMMIT_MSG | grep -o "Redmine Milestone: .*" | awk '{print $3}') -export REDMINE_QUERY_URL=$(echo $COMMIT_MSG | grep -o "Redmine Query: .*" | awk '{print $3}') - -echo "Releasing $RELEASE" -echo "Milestone URL: $MILESTONE_URL" -echo "Query: $REDMINE_QUERY_URL" - -pip install python-redmine httpie - -python3 .ci/scripts/redmine.py $REDMINE_QUERY_URL $MILESTONE_URL $RELEASE diff --git a/.ci/scripts/validate_commit_message.py b/.ci/scripts/validate_commit_message.py index e25162ec..a96876b0 100755 --- a/.ci/scripts/validate_commit_message.py +++ b/.ci/scripts/validate_commit_message.py @@ -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): diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ad27ac84..be906422 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 }} diff --git a/.github/workflows/scripts/check_commit.sh b/.github/workflows/scripts/check_commit.sh index 59a406f0..5b569f82 100755 --- a/.github/workflows/scripts/check_commit.sh +++ b/.github/workflows/scripts/check_commit.sh @@ -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') diff --git a/.github/workflows/scripts/release.py b/.github/workflows/scripts/release.py index 7826c494..0156f53f 100755 --- a/.github/workflows/scripts/release.py +++ b/.github/workflows/scripts/release.py @@ -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): """ @@ -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 @@ -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) @@ -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 diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index dcee4c7b..b89efb42 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -21,7 +21,7 @@ Changelog update The CHANGES.rst file is managed using the `towncrier tool `_ 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 diff --git a/docs/index.rst b/docs/index.rst index d6a71762..2c95332c 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -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 `_ + 1. `Github Issues `_ 2. `Github Pull Requests `_ 3. `Helping other users `_ diff --git a/pyproject.toml b/pyproject.toml index c0d729de..cd456e05 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ filename = "CHANGES.rst" directory = "CHANGES/" title_format = "{version} ({project_date})" template = "CHANGES/.TEMPLATE.rst" -issue_format = "`#{issue} `_" +issue_format = "`#{issue} `_" [tool.black] line-length = 100 diff --git a/template_config.yml b/template_config.yml index 9629f29e..e69c994e 100644 --- a/template_config.yml +++ b/template_config.yml @@ -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 @@ -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