#22 [frontend] handle GitHub tag event webhooks
Merged 7 years ago by clime. Opened 7 years ago by ktdreyer.
copr/ ktdreyer/copr handle-tag-webhooks  into  master

@@ -116,6 +116,9 @@ 

  

      @classmethod

      def commits_belong_to_package(cls, package, payload):

+         if payload.get("ref_type", None) == "tag":

+             return True

+ 

          ref = payload.get("ref", "")

  

          if package.source_type_text == "git_and_tito":

@@ -43,7 +43,7 @@ 

      </label>

      <div class="col-sm-10">

        <input type="checkbox" name="webhook_rebuild" {% if form.webhook_rebuild.data == True %}checked="checked"{% endif %}/>

-       Use webhook to rebuild package? (i.e. every commit in git repository)

+       Use webhook to rebuild package? (i.e. every commit or tag in git repository)

        | See <a href="{{ copr_url('coprs_ns.copr_webhooks', copr) }}">Webhooks Settings</a>

      </div>

    </div>

@@ -23,7 +23,7 @@ 

            <li> Use the webhook URL from this project in your Git (see below). </li>

          </ol>

          <p> Copr will now rebuild the package every time it receives the webhook

-             call - usually with every commit. </p>

+             call - usually with every commit or every tag. </p>

  

          <h4> Webhook URL for GitHub </h4>

          <div class="well well-sm">

Prior to this change, if a user enabled GitHub webhooks for "create" events in GitHub (eg tag creations), then Copr would not rebuild packages for those webhooks.

From https://developer.github.com/v3/activity/events/types/#createevent, the "tag creation" webhook looks like so:

{
  "ref": "0.0.1",
  "ref_type": "tag",
  ...
}

In this case "ref" is not a branch name, but a Git tag. We should not attempt to compare this tag name to the branch name in the commits_belong_to_package() method.

The goal with this change is to allow me to rebuild packages when I push new tags, rather than building every commit.

Do you think the same could be done for "git_and_tito" method?

@clime I'm sorry I don't used Tito (it has some unfortunate limitations at the moment, eg https://github.com/dgoodwin/tito/issues/146) so I'm not familiar with how that works

Logic in this method is of kind of "rule-out". If none of the conditions is satisfied in the method, return True in the end. It's kind of strange. In this case, the whole if/elif should be conditioned by ref_type being "branch" so that inner conditions that compare branch names make sense. This will also provide support for GitAndTito at the same time.

I looked into restructuring this in the "rule-out" pattern you describe, but GitHub's PushEvents do not have "ref_type": "branch" in the payload - in fact there is no ref_type at all for PushEvents.

I've moved the conditional to the top of the method so it applies for both GitAndTito and MockSCM.

rebased

7 years ago

Pull-Request has been merged by clime

7 years ago