# Copyright 2018 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import re from zuul.model import Change, TriggerEvent, EventFilter, RefFilter EMPTY_GIT_REF = '0' * 40 # git sha of all zeros, used during creates/deletes class PullRequest(Change): def __init__(self, project): super(PullRequest, self).__init__(project) self.project = None self.pr = None self.updated_at = None self.title = None self.score = 0 self.files = [] self.tags = [] self.status = None def __repr__(self): r = ['' def isUpdateOf(self, other): if (self.project == other.project and hasattr(other, 'number') and self.number == other.number and hasattr(other, 'updated_at') and self.updated_at > other.updated_at): return True return False class PagureTriggerEvent(TriggerEvent): def __init__(self): super(PagureTriggerEvent, self).__init__() self.trigger_name = 'pagure' self.title = None self.action = None self.status = None self.tags = [] self.tag = None def toDict(self): d = super().toDict() d["trigger_name"] = self.trigger_name d["title"] = self.title d["action"] = self.action d["status"] = self.status d["tags"] = list(self.tags) d["tag"] = self.tag return d def updateFromDict(self, d): super().updateFromDict(d) self.trigger_name = d.get("trigger_name", "pagure") self.title = d.get("title") self.action = d.get("action") self.status = d.get("status") self.tags = d.get("tags", []) self.tag = d.get("tag") def _repr(self): r = [super(PagureTriggerEvent, self)._repr()] if self.action: r.append("action:%s" % self.action) if self.status: r.append("status:%s" % self.status) r.append("project:%s" % self.canonical_project_name) if self.change_number: r.append("pr:%s" % self.change_number) if self.tags: r.append("tags:%s" % ', '.join(self.tags)) return ' '.join(r) def isPatchsetCreated(self): if self.type == 'pg_pull_request': return self.action in ['opened', 'changed'] return False class PagureEventFilter(EventFilter): def __init__(self, connection_name, trigger, types=[], refs=[], statuses=[], comments=[], actions=[], tags=[], ignore_deletes=True): EventFilter.__init__(self, connection_name, trigger) self._types = types self._refs = refs self._comments = comments self.types = [re.compile(x) for x in types] self.refs = [re.compile(x) for x in refs] self.comments = [re.compile(x) for x in comments] self.actions = actions self.statuses = statuses self.tags = tags self.ignore_deletes = ignore_deletes def __repr__(self): ret = '