diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-09-25 13:34:37 -0400 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-09-25 13:34:37 -0400 |
commit | 1d86747777d81bd38e273f0a4affb1d5dfba1ac7 (patch) | |
tree | e904af1ec27d83aef9ad2e8179874605ce79c48e | |
parent | f062632c9143eed0597a470535f152e2412cff3e (diff) | |
download | korg-helpers-1d86747777d81bd38e273f0a4affb1d5dfba1ac7.tar.gz |
Fixes for git-patchwork-bot and an example.yaml
Finally, provide an example config file that everyone's been wanting.
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r-- | git-patchwork-bot.example.yaml | 159 | ||||
-rwxr-xr-x | git-patchwork-bot.py | 39 |
2 files changed, 181 insertions, 17 deletions
diff --git a/git-patchwork-bot.example.yaml b/git-patchwork-bot.example.yaml new file mode 100644 index 0000000..61140f5 --- /dev/null +++ b/git-patchwork-bot.example.yaml @@ -0,0 +1,159 @@ +--- +patchworks: + # Entries are full URLs to the patchwork server toplevel + 'https://patchwork.kernel.org': + # You can use an API token, or you can add username/password + # to the $HOME/.netrc file + apitoken: 'your-api-token' + projects: + # URL subpath name of the project + 'linux-amlogic': + # Email will go out from this address + from: 'patchwork-bot+linux-amlogic@kernel.org' + # Any summaries will be sent to these addresses + summaryto: + - 'developer@example.com' + - 'developer@example.org' + # If this is set, all emails from the bot will be + # cc'd to the list + cclist: true + # When run with -k + housekeeping: + # Automatically supersede new series coming in from the same + # author and with the exact same subject (sans prefixes). This + # setting tells us how many days back we should look to find a + # matching series. + autosupersede: 30 + # Archive any patches older than this number of days. + autoarchive: 90 + + 'git': + from: 'patchwork-bot+git@kernel.org' + summaryto: + - 'developer@example.com' + - 'developer@example.org' + housekeeping: + autosupersede: 90 + autoarchive: 180 + + 'https://lore.kernel.org/patchwork': + apitoken: 'another-api-token' + projects: + 'lkml': + from: 'notify+lkml@kernel.org' + summaryto: + - 'developer@example.net' + housekeeping: + autosupersede: 30 + autoarchive: 180 + +repos: + # Each entry is a subpath to a repo from the --reposdir toplevel + 'pub/scm/linux/kernel/git/khilman/linux-amlogic.git': + # For the notification emails + treename: 'khilman/linux-amlogic.git' + # For the notification emails, must include %s + commitlink: 'https://git.kernel.org/khilman/linux-amlogic/c/%.12s' + # Only notify for commits where committer email exactly matches one + # of the emails listed below + committers: + - 'khilman@example.org' + # Which projects should be consulted on all new commits + projects: + # The project name MUST match one of the projects defined in patchworks: + # This necessarily means that the project name must be unique across all + # defined patchwork servers. + 'linux-amlogic': + # entries are head names in the repository + # e.g. this one is for refs/heads/example + # They are matched with 'endswith' against the full refname + 'example': + # Default "fromstate" is "new" or "in-review" + # This is the state we will set on all matching patches + tostate: 'Queued' + # Send summary about changes to the people defined in "summaryto" + send_summary: true + 'for-next': + # If you add a new fromstate, you have to specify the default ones + fromstate: + - 'new' + - 'in-review' + - 'queued' + tostate: 'Accepted' + send_summary: true + # Notify submitters when their patches change state. + # The bot will send a single email per series. + notify_submitter: true + # CC the list on submitter notifications. + # Note, that summaries will be sent to the list as well, if + # send_summary is true. + cclist: true + 'fixes': + fromstate: + - 'new' + - 'in-review' + - 'queued' + tostate: 'Accepted' + send_summary: true + notify_submitter: true + cclist: true + + 'pub/scm/linux/kernel/git/torvalds/linux.git': + treename: 'torvalds/linux.git' + commitlink: 'https://git.kernel.org/torvalds/c/%.12s' + projects: + 'lkml': + 'master': + fromstate: + - 'new' + - 'in-next' + tostate: 'Accepted' + notify_submitter: true + # We only notify if the below address is in the cc list + onlyifcc: + - 'notify@kernel.org' + + 'pub/scm/linux/kernel/git/next/linux-next.git': + treename: 'next/linux-next.git' + commitlink: 'https://git.kernel.org/next/linux-next/c/%.12s' + projects: + 'lkml': + 'master': + tostate: 'In Next' + notify_submitter: true + # Single-value arrays can be defined as strings as well + onlyifcc: 'notify@kernel.org' + +# The below templates are self-explanatory +# yamllint disable rule:line-length +templates: + summary: | + Hello: + + The following patches were marked "${newstate}", because they were applied to + ${treename} (${refname}): + + ${summary} + + Total patches: ${total} + + -- + ${signature} + submitter: | + Hello: + + This ${reqtype} was applied to ${treename} (${refname}): + + On ${sentdate} you wrote: + ${trimquote} + + Here is the summary with links: + ${summary} + + You are awesome, thank you! + -- + ${signature} + signature: | + Deet-doot-dot, I am a bot. + https://korg.docs.kernel.org/patchwork/pwbot.html +# yamllint enable diff --git a/git-patchwork-bot.py b/git-patchwork-bot.py index a2cdc1e..9bf357c 100755 --- a/git-patchwork-bot.py +++ b/git-patchwork-bot.py @@ -6,12 +6,7 @@ # additionally send mail notifications to the maintainers and to the # patch submitters. # -# While we continue to support the 1.1 API, we must rely on -# username/password authentication. To make that work, set up the -# $HOME/.netrc file. Once we drop support for patchwork < 2.2, we'll -# switch over to using the API keys entirely. -# -# It runs from a cronjob, but can be also run from post-update hooks with +# It runs from a cronjob, but can be also run from post-update hooks with # extra wrappers. For more details, consult: # # https://korg.wiki.kernel.org/userdoc/pwbot @@ -94,11 +89,14 @@ class Transport(xmlrpclib.SafeTransport): self.host = host if self.proxy: host = self.proxy.split('://', 1)[-1].rstrip('/') - nc = netrc.netrc() - auths = nc.authenticators(host) - if auths: - login, account, password = auths - host = '{}:{}@{}'.format(login, password, host) + try: + nc = netrc.netrc() + auths = nc.authenticators(host) + if auths: + login, account, password = auths + host = f'{login}:{password}@{host}' + except FileNotFoundError: + pass if self.https: return xmlrpclib.SafeTransport.make_connection(self, host) else: @@ -126,7 +124,13 @@ class Restmaker: adapter = HTTPAdapter(max_retries=retry) self.session.mount('http://', adapter) self.session.mount('https://', adapter) - self.session.headers.update({'User-Agent': 'git-patchwork-bot/%s' % __VERSION__}) + headers = { + 'User-Agent': f'git-patchwork-bot/{__VERSION__}', + } + apitoken = CONFIG['patchworks'][server].get('apitoken', None) + if apitoken: + headers['Authorization'] = f'Token {apitoken}' + self.session.headers.update(headers) def get_cover(self, cover_id): try: @@ -589,7 +593,7 @@ def send_summary(serieslist, to_state, refname, pname, rs, hs): msg.replace_header('Content-Transfer-Encoding', '8bit') msg['Subject'] = Header('Patchwork summary for: %s' % pname) - msg['From'] = Header(pconfig['from']) + msg['From'] = Header(tweaks['from']) msg['Message-Id'] = make_msgid('git-patchwork-summary', domain=DOMAIN) msg['Date'] = formatdate(localtime=True) @@ -607,7 +611,7 @@ def send_summary(serieslist, to_state, refname, pname, rs, hs): logger.info('Sending summary to: %s', msg['To']) smtp = smtplib.SMTP(MAILHOST) - smtp.sendmail(msg['From'], targets, msg.as_bytes()) + smtp.sendmail(tweaks['from'], targets, msg.as_bytes()) smtp.close() else: logger.info('Would have sent the following:') @@ -615,7 +619,7 @@ def send_summary(serieslist, to_state, refname, pname, rs, hs): logger.info(msg.as_string()) logger.info('------------------------------') - return msg['Message-Id'] + return str(msg['Message-Id']) def get_tweaks(pconfig, hconfig): @@ -770,7 +774,7 @@ def notify_submitters(serieslist, refname, revs, pname, rs, hs): logger.info('Notifying %s', submitter.get('email')) smtp = smtplib.SMTP(MAILHOST) - smtp.sendmail(msg['From'], targets, msg.as_bytes()) + smtp.sendmail(tweaks['from'], targets, msg.as_bytes()) smtp.close() else: logger.info('Would have sent the following:') @@ -1002,7 +1006,7 @@ def housekeeping(pname): logger.info('Sending housekeeping summary to: %s', msg['To']) smtp = smtplib.SMTP(MAILHOST) - smtp.sendmail(msg['From'], targets, msg.as_bytes()) + smtp.sendmail(pconfig['from'], targets, msg.as_bytes()) smtp.close() else: logger.info('Would have sent the following:') @@ -1097,6 +1101,7 @@ def pwrun(repo, rsettings): rpwhashes[refname].add((rev, logline, pwhash)) rcdbconn.commit() + rcdbconn.close() if not wantstates: wantstates = ['new', 'under-review'] |