def test_add_to_tags_str(self): T.assert_equal("A", add_to_tags_str("", "A")) T.assert_equal("A", add_to_tags_str("A", "A")) T.assert_equal("A,B", add_to_tags_str("A", "B")) T.assert_equal("A,B,C", add_to_tags_str("A,B", "C")) T.assert_equal("A,B,C", add_to_tags_str("A,B,C", "C")) T.assert_equal("A,B,C", add_to_tags_str("A", "A,B,C")) T.assert_equal("A,B", add_to_tags_str("A", "B")) T.assert_equal("A,B,C", add_to_tags_str("B,A", "C")) T.assert_equal("A,B,C", add_to_tags_str("A,C,B", "C")) T.assert_equal("A,B,C", add_to_tags_str("A", "B,A,C"))
def update_request(cls, request_id): req = cls._get_request(request_id) if not req: # Just log this and return. We won't be able to get more # data out of the request. error_msg = "Git queue worker received a job for non-existent request id %s" % request_id logging.error(error_msg) return if cls.request_is_excluded_from_git_verification(req): return if not req['branch']: error_msg = "Git queue worker received a job for request with no branch (id %s)" % request_id return cls.update_request_failure(req, error_msg) sha = cls._get_branch_sha_from_repo(req) if sha is None: error_msg = "Git queue worker could not get the revision from request branch (id %s)" % request_id return cls.update_request_failure(req, error_msg) duplicate_req = cls._get_request_with_sha(sha) if duplicate_req and duplicate_req.has_key( 'state') and not duplicate_req['state'] == "discarded": error_msg = "Git queue worker found another request with the same revision sha (ids %s and %s)" % ( duplicate_req['id'], request_id) return cls.update_request_failure(req, error_msg) updated_tags = add_to_tags_str(req['tags'], 'git-ok') updated_tags = del_from_tags_str(updated_tags, 'git-error') updated_values = {'revision': sha, 'tags': updated_tags} updated_request = cls._update_request(req, updated_values) if updated_request: cls.update_request_successful(updated_request)
def convert_tag_callback(oldtag, newtag, success, db_results): check_db_results(success, db_results) requests = db_results[0].fetchall() update_queries = [] for request in requests: if tags_contain(request['tags'], [oldtag]): updated_tags = del_from_tags_str(request['tags'], oldtag) updated_tags = add_to_tags_str(updated_tags, newtag) update_query = db.push_requests.update().where( db.push_requests.c.id == request.id ).values({'tags': updated_tags}) update_queries.append(update_query) db.execute_transaction_cb(update_queries, check_db_results)
def update_request_failure(cls, request, failure_msg): logging.error(failure_msg) updated_tags = add_to_tags_str(request['tags'], 'git-error') updated_tags = del_from_tags_str(updated_tags, 'git-ok') updated_values = {'tags': updated_tags} cls._update_request(request, updated_values) msg = (""" <p> <em>PushManager could <strong>not</strong> verify the branch for your request.</em> </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em><br /> <a href="https://%(pushmanager_servername)s/request?id=%(id)s">https://%(pushmanager_servername)s/request?id=%(id)s</a> </p> <p> <strong>Error message</strong>:<br /> %(failure_msg)s </p> <p> Review # (if specified): <a href="https://%(reviewboard_servername)s/r/%(reviewid)s">%(reviewid)s</a> </p> <p> Verified revision: <code>%(revision)s</code><br/> <em>(If this is <strong>not</strong> the revision you expected, make sure you've pushed your latest version to the correct repo!)</em> </p> <p> Regards,<br/> PushManager </p> """) request.update({ 'failure_msg': failure_msg, 'pushmanager_servername': Settings['main_app']['servername'], 'reviewboard_servername': Settings['reviewboard']['servername'] }) msg %= EscapedDict(request) subject = '[push] %s - %s' % (request['user'], request['title']) user_to_notify = request['user'] MailQueue.enqueue_user_email([user_to_notify], msg, subject)
def update_request_failure(cls, request, failure_msg): logging.error(failure_msg) updated_tags = add_to_tags_str(request["tags"], "git-error") updated_tags = del_from_tags_str(updated_tags, "git-ok") updated_values = {"tags": updated_tags} cls._update_request(request, updated_values) msg = """ <p> <em>PushManager could <strong>not</strong> verify the branch for your request.</em> </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em><br /> <a href="https://%(pushmanager_servername)s/request?id=%(id)s">https://%(pushmanager_servername)s/request?id=%(id)s</a> </p> <p> <strong>Error message</strong>:<br /> %(failure_msg)s </p> <p> Review # (if specified): <a href="https://%(reviewboard_servername)s/r/%(reviewid)s">%(reviewid)s</a> </p> <p> Verified revision: <code>%(revision)s</code><br/> <em>(If this is <strong>not</strong> the revision you expected, make sure you've pushed your latest version to the correct repo!)</em> </p> <p> Regards,<br/> PushManager </p> """ request.update( { "failure_msg": failure_msg, "pushmanager_servername": Settings["main_app"]["servername"], "reviewboard_servername": Settings["reviewboard"]["servername"], } ) msg %= EscapedDict(request) subject = "[push] %s - %s" % (request["user"], request["title"]) user_to_notify = request["user"] MailQueue.enqueue_user_email([user_to_notify], msg, subject)
def update_request_failure(cls, request, failure_msg): logging.error(failure_msg) updated_tags = add_to_tags_str(request['tags'], 'git-error') updated_tags = del_from_tags_str(updated_tags, 'git-ok') updated_values = {'tags': updated_tags} cls._update_request(request, updated_values) msg = ( """ <p> <em>PushManager could <strong>not</strong> verify the branch for your request.</em> </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em><br /> <a href="https://%(pushmanager_servername)s/request?id=%(id)s">https://%(pushmanager_servername)s/request?id=%(id)s</a> </p> <p> <strong>Error message</strong>:<br /> %(failure_msg)s </p> <p> Review # (if specified): <a href="https://%(reviewboard_servername)s/r/%(reviewid)s">%(reviewid)s</a> </p> <p> Verified revision: <code>%(revision)s</code><br/> <em>(If this is <strong>not</strong> the revision you expected, make sure you've pushed your latest version to the correct repo!)</em> </p> <p> Regards,<br/> PushManager </p> """) request.update({ 'failure_msg': failure_msg, 'pushmanager_servername': Settings['main_app']['servername'], 'reviewboard_servername': Settings['reviewboard']['servername'] }) msg %= EscapedDict(request) subject = '[push] %s - %s' % (request['user'], request['title']) user_to_notify = request['user'] MailQueue.enqueue_user_email([user_to_notify], msg, subject)
def update_request(cls, request_id): req = cls._get_request(request_id) if not req: # Just log this and return. We won't be able to get more # data out of the request. error_msg = "Git queue worker received a job for non-existent request id %s" % request_id logging.error(error_msg) return if cls.request_is_excluded_from_git_verification(req): return if not req['branch']: error_msg = "Git queue worker received a job for request with no branch (id %s)" % request_id return cls.update_request_failure(req, error_msg) sha = cls._get_branch_sha_from_repo(req) if sha is None: error_msg = "Git queue worker could not get the revision from request branch (id %s)" % request_id return cls.update_request_failure(req, error_msg) duplicate_req = cls._get_request_with_sha(sha) if duplicate_req and duplicate_req.has_key('state') and not duplicate_req['state'] == "discarded": error_msg = "Git queue worker found another request with the same revision sha (ids %s and %s)" % ( duplicate_req['id'], request_id ) return cls.update_request_failure(req, error_msg) updated_tags = add_to_tags_str(req['tags'], 'git-ok') updated_tags = del_from_tags_str(updated_tags, 'git-error') updated_values = {'revision': sha, 'tags': updated_tags} updated_request = cls._update_request(req, updated_values) if updated_request: cls.update_request_successful(updated_request)