| |
@@ -40,31 +40,35 @@
|
| |
|
| |
log.info("ENDPOINT = {}".format(ENDPOINT))
|
| |
|
| |
- TOPICS = {
|
| |
- 'io.pagure.prod.pagure.git.receive': 'https://pagure.io/',
|
| |
- 'io.pagure.prod.pagure.pull-request.new': 'https://pagure.io/',
|
| |
- 'io.pagure.prod.pagure.pull-request.comment.added': 'https://pagure.io/',
|
| |
- 'org.fedoraproject.prod.pagure.git.receive': 'https://src.fedoraproject.org/',
|
| |
- 'org.fedoraproject.prod.pagure.pull-request.new': 'https://src.fedoraproject.org/',
|
| |
- 'org.fedoraproject.prod.pagure.pull-request.comment.added': 'https://src.fedoraproject.org/',
|
| |
- 'io.pagure.stg.pagure.git.receive': 'https://stg.pagure.io/', # testing only
|
| |
- 'io.pagure.stg.pagure.pull-request.new': 'https://stg.pagure.io/', # testing only
|
| |
- 'io.pagure.stg.pagure.pull-request.comment.added': 'https://stg.pagure.io/', # testing only
|
| |
+ pagure_instances = {
|
| |
+ 'https://pagure.io/': 'io.pagure.prod.pagure',
|
| |
+ 'https://src.fedoraproject.org/': 'org.fedoraproject.prod.pagure',
|
| |
+ 'https://stg.pagure.io/': 'io.pagure.stg.pagure', # testing only
|
| |
}
|
| |
|
| |
+ topics = [
|
| |
+ 'git.receive',
|
| |
+ 'pull-request.new',
|
| |
+ 'pull-request.rebased',
|
| |
+ 'pull-request.updated',
|
| |
+ 'pull-request.comment.added',
|
| |
+ ]
|
| |
+
|
| |
+ TOPICS = {}
|
| |
+ for url, fedmsg_prefix in pagure_instances.items():
|
| |
+ for topic in topics:
|
| |
+ TOPICS['{0}.{1}'.format(fedmsg_prefix, topic)] = url
|
| |
+
|
| |
|
| |
class ScmPackage(object):
|
| |
def __init__(self, db_row):
|
| |
- self.pkg_id = db_row.package_id
|
| |
- self.copr_id = db_row.copr_id
|
| |
-
|
| |
self.source_json_dict = json.loads(db_row.source_json)
|
| |
self.clone_url = self.source_json_dict.get('clone_url') or ''
|
| |
self.committish = self.source_json_dict.get('committish') or ''
|
| |
self.subdirectory = self.source_json_dict.get('subdirectory') or ''
|
| |
|
| |
- self.package = ComplexLogic.get_package_by_id_safe(self.pkg_id)
|
| |
- self.copr = ComplexLogic.get_copr_by_id_safe(self.copr_id)
|
| |
+ self.package = ComplexLogic.get_package_by_id_safe(db_row.package_id)
|
| |
+ self.copr = self.package.copr
|
| |
|
| |
def build(self, source_dict_update, copr_dir, update_callback,
|
| |
scm_object_type, scm_object_id, scm_object_url):
|
| |
@@ -75,10 +79,6 @@
|
| |
package = self.package
|
| |
|
| |
db.session.execute('LOCK TABLE build IN EXCLUSIVE MODE')
|
| |
- if models.Build.query.filter(models.Build.scm_object_url == scm_object_url).first():
|
| |
- log.info('\t -> Build for {} already exists.'.format(scm_object_url))
|
| |
- return None
|
| |
-
|
| |
return BuildsLogic.rebuild_package(
|
| |
package, source_dict_update, copr_dir, update_callback,
|
| |
scm_object_type, scm_object_id, scm_object_url)
|
| |
@@ -116,7 +116,7 @@
|
| |
return False
|
| |
|
| |
|
| |
- def event_info_from_pr_update(data, base_url):
|
| |
+ def event_info_from_pr_comment(data, base_url):
|
| |
"""
|
| |
Message handler for updated pull-request opened in pagure.
|
| |
Topic: ``*.pagure.pull-request.comment.added``
|
| |
@@ -130,8 +130,12 @@
|
| |
return False
|
| |
|
| |
last_comment = data['msg']['pullrequest']['comments'][-1]
|
| |
- if not last_comment or last_comment['notification'] is False:
|
| |
- log.info('Comment was not a notification, discarding.')
|
| |
+ if not last_comment:
|
| |
+ log.info('Can not access last comment, discarding.')
|
| |
+ return False
|
| |
+
|
| |
+ if not 'comment' in last_comment or '[copr-build]' not in last_comment['comment']:
|
| |
+ log.info('The [copr-build] is not present in the message.')
|
| |
return False
|
| |
|
| |
return munch.Munch({
|
| |
@@ -150,7 +154,7 @@
|
| |
})
|
| |
|
| |
|
| |
- def event_info_from_new_pr(data, base_url):
|
| |
+ def event_info_from_pr(data, base_url):
|
| |
"""
|
| |
Message handler for new pull-request opened in pagure.
|
| |
Topic: ``*.pagure.pull-request.new``
|
| |
@@ -233,10 +237,10 @@
|
| |
log.error('Unknown topic {} received. Continuing.')
|
| |
continue
|
| |
|
| |
- if re.match(r'^.*.pull-request.new$', data['topic']):
|
| |
- event_info = event_info_from_new_pr(data, base_url)
|
| |
+ if re.match(r'^.*.pull-request.(new|rebased|updated)$', data['topic']):
|
| |
+ event_info = event_info_from_pr(data, base_url)
|
| |
elif re.match(r'^.*.pull-request.comment.added$', data['topic']):
|
| |
- event_info = event_info_from_pr_update(data, base_url)
|
| |
+ event_info = event_info_from_pr_comment(data, base_url)
|
| |
else:
|
| |
event_info = event_info_from_push(data, base_url)
|
| |
|
| |
@@ -259,7 +263,13 @@
|
| |
log.error('Bad http status {0} from url {1}'.format(r.status_code, raw_commit_url))
|
| |
|
| |
for pkg in candidates:
|
| |
- log.info('Considering pkg id: {}, source_json: {}'.format(pkg.pkg_id, pkg.source_json_dict))
|
| |
+ package = '{}/{}(id={})'.format(
|
| |
+ pkg.package.copr.full_name,
|
| |
+ pkg.package.name,
|
| |
+ pkg.package.id
|
| |
+ )
|
| |
+ log.info('Considering pkg package: {}, source_json: {}'
|
| |
+ .format(package, pkg.source_json_dict))
|
| |
|
| |
if (git_compare_urls(pkg.clone_url, event_info.base_clone_url)
|
| |
and (not pkg.committish or event_info.branch_to.endswith(pkg.committish))
|
| |
@@ -271,8 +281,8 @@
|
| |
dirname = pkg.copr.name + ':pr:' + str(event_info.object_id)
|
| |
copr_dir = CoprDirsLogic.get_or_create(pkg.copr, dirname)
|
| |
update_callback = 'pagure_flag_pull_request'
|
| |
- scm_object_url = os.path.join(base_url, event_info.base_project_url_path,
|
| |
- 'pull-request', str(event_info.object_id))
|
| |
+ scm_object_url = os.path.join(base_url, event_info.project_url_path,
|
| |
+ 'c', str(event_info.end_commit))
|
| |
else:
|
| |
copr_dir = pkg.copr.main_dir
|
| |
update_callback = 'pagure_flag_commit'
|
| |
Previously, if even only one build existed in database for
particular commit hash in pagure (regardless of the package or
copr project), the pagure-events.py did not start the build.
The most frequent problem would be in forked projects probably;
project forks inherit packages with theirs SCM configuration and
then automatically one pull-requests means multiple builds. The
previous code though built only into one project (randomly).
Fixes: #586