From 1841ba4be923cf5a19375754efe56f039d3fa000 Mon Sep 17 00:00:00 2001 From: James Douglass Date: Fri, 25 Oct 2019 10:35:52 -0700 Subject: [PATCH] Add a plugin to prefix an issue number with a user-defined string. --- plugins/issue_prefix/README.md | 19 +++++++++++++++++++ plugins/issue_prefix/__init__.py | 15 +++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 plugins/issue_prefix/README.md create mode 100644 plugins/issue_prefix/__init__.py diff --git a/plugins/issue_prefix/README.md b/plugins/issue_prefix/README.md new file mode 100644 index 00000000..0c515376 --- /dev/null +++ b/plugins/issue_prefix/README.md @@ -0,0 +1,19 @@ +## Issue Prefix + +When migrating to other source code hosting sites, there are cases where a +project maintainer might want to reset their issue tracker and not have old +issue numbers in commit messages referring to the wrong issue. One way around +this is to prefix issue numbers with some other string. + +If migrating to GitHub, this issue prefixing can be paired with GitHub's +autolinking capabilitiy to link back to a different issue tracker: +https://help.github.com/en/github/administering-a-repository/configuring-autolinks-to-reference-external-resources + +To use this plugin, add: +`--plugin=issue_prefix=` + +Example: +`--plugin=issue_prefix=BB-` + +This will prefix issue numbers with the string `BB-`. Example: `#123` will +change to `#BB-123`. diff --git a/plugins/issue_prefix/__init__.py b/plugins/issue_prefix/__init__.py new file mode 100644 index 00000000..b5a0fc64 --- /dev/null +++ b/plugins/issue_prefix/__init__.py @@ -0,0 +1,15 @@ +# encoding=UTF-8 +"""__init__.py""" +import re + +def build_filter(args): + return Filter(args) + +class Filter: + def __init__(self, args): + self.prefix = args + + def commit_message_filter(self, commit_data): + for match in re.findall('#[1-9][0-9]+', commit_data['desc']): + commit_data['desc'] = commit_data['desc'].replace( + match, '#%s%s' % (self.prefix, match[1:]))