|
|
@ -25,8 +25,6 @@ import functools |
|
|
|
import typing |
|
|
|
|
|
|
|
import attr |
|
|
|
import jenkins |
|
|
|
import requests |
|
|
|
|
|
|
|
|
|
|
|
def _list_helper( |
|
|
@ -76,7 +74,7 @@ class ReleaseBotTask(object): |
|
|
|
""" |
|
|
|
|
|
|
|
id = attr.ib(type=str) |
|
|
|
repo_store = attr.ib(repr=False, type= "GenericRepoStore") |
|
|
|
repo_store = attr.ib(repr=False, type="GenericRepoStore") |
|
|
|
command = attr.ib(type=ReleaseBotCommand) |
|
|
|
requester = attr.ib(type=ReleaseBotRequester) |
|
|
|
message = attr.ib(default="", type=str) |
|
|
@ -152,6 +150,9 @@ class GiteaRepoStore(GenericRepoStore): |
|
|
|
# These could be overridden in the config, but we have sane defaults |
|
|
|
self.gitea_org = self.config.get("git", "gitea_org", fallback=self.namespace) |
|
|
|
self.gitea_team = self.config.get("git", "gitea_team", fallback="packages") |
|
|
|
|
|
|
|
import requests |
|
|
|
|
|
|
|
try: |
|
|
|
# python-requests 3 |
|
|
|
self._http = requests.HTTPSession() |
|
|
@ -323,6 +324,8 @@ class JenkinsJobStore(GenericJobStore): |
|
|
|
def __init__(self, config, args): |
|
|
|
super().__init__(config, args) |
|
|
|
# Connect to Jenkins |
|
|
|
import jenkins |
|
|
|
|
|
|
|
self.jk = jenkins.Jenkins( |
|
|
|
self.config.get("jenkins", "host"), |
|
|
|
self.config.get("jenkins", "username"), |
|
|
@ -368,10 +371,6 @@ class ReleaseBot(object): |
|
|
|
for task in self.repo_store.get_pending_tasks(): |
|
|
|
yield self._process_task(task) |
|
|
|
|
|
|
|
def cmd_build(self, task: ReleaseBotTask): |
|
|
|
for suite in task.command.labels: |
|
|
|
self.job_store.queue_build(suite, task.command.package) |
|
|
|
|
|
|
|
def _process_task(self, task: ReleaseBotTask) -> ReleaseBotTask: |
|
|
|
# 0. Check command is valid |
|
|
|
cmd = getattr(self, "cmd_{}".format(task.command.name), None) |
|
|
@ -389,9 +388,18 @@ class ReleaseBot(object): |
|
|
|
task.resolve_notify('Command not supported: "{}"'.format(task.command.name)) |
|
|
|
return task |
|
|
|
|
|
|
|
def cmd_build(self, task: ReleaseBotTask): |
|
|
|
for suite in task.command.labels: |
|
|
|
url = self.job_store.queue_build(suite, task.command.package) |
|
|
|
task.notify( |
|
|
|
'Triggered "{}" build for "{}": {}'.format( |
|
|
|
task.command.package, suite, url |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
def label_is_restricted(self, suite: str) -> bool: |
|
|
|
""" |
|
|
|
A label is considered restricted if on of following match: |
|
|
|
A label is considered restricted if one of following match: |
|
|
|
- It starts with a restricted suite |
|
|
|
- It ends with a restricted suffix |
|
|
|
""" |
|
|
@ -461,8 +469,6 @@ def main(config, args): |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
import sys |
|
|
|
|
|
|
|
args = get_argparser().parse_args() |
|
|
|
|
|
|
|
if args.config.name != "<stdin>" and not isinstance(args.config.name, int): |
|
|
@ -471,6 +477,8 @@ if __name__ == "__main__": |
|
|
|
# Eargsure the config file with secrets is mode 0600 or 0400 |
|
|
|
# This check is skipped if config is passed via stdin or file descriptor |
|
|
|
if os.stat(args.config.name).st_mode & 0o177 != 0: |
|
|
|
import sys |
|
|
|
|
|
|
|
sys.stderr.write( |
|
|
|
"Permissions are too broad ({})\n".format(args.config.name) |
|
|
|
) |
|
|
|