Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use PullRequest PipelineResource to update status #1777

Closed
bobcatfish opened this issue Dec 19, 2019 · 3 comments
Closed

Can't use PullRequest PipelineResource to update status #1777

bobcatfish opened this issue Dec 19, 2019 · 3 comments
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@bobcatfish
Copy link
Collaborator

Expected Behavior

I should be able to use the PullRequest resource to update the status on a PR.

Actual Behavior

When I try to update my "poop" status, it fails and I get this in the logs from pullrequest-init/main.go:72:

1 error occurred:\n\t* creating status \"poop\": Not Found\n\n","resource_type":"pullrequest","mode":"upload","stacktrace":"main.main\n\tgithub.com/tektoncd/pipeline@/cmd/pullrequest-init/main.go:72\nruntime.main\n\truntime/proc.go:203

Steps to Reproduce the Problem

I was using this Task:

apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
  name: set-status
spec:
  inputs:
    resources:
    - name: pr
      type: pullRequest
    params:
    - name: status
      type: string
  outputs:
    resources:
    - name: pr
      type: pullRequest
  steps:
  - name: set
    image: ubuntu
    command: ['bash']
    args:
    - -c
    - |
        set -ex
        cp -r /workspace/pr/ /workspace/output/
        ls -laR /workspace/output
        cat <<EOF > /workspace/output/pr/status/poop.json
        {
          "Label": "poop",
          "State": "$(inputs.params.status)",
          "Desc": "Tekton is running"
        }
        EOF
        ls -laR /workspace/output

With this Pipeline:

apiVersion: tekton.dev/v1alpha1
kind: Pipeline
metadata:
  name: git-admission-control
spec:
  params:
  - name: event-body
  resources:
  - name: pull-request
    type: pullRequest
  - name: policy-repo
    type: git
  tasks:
  - name: setstatus-inprogress
    taskRef:
      name: set-status
    resources:
      inputs:
      - name: pr
        resource: pull-request
      outputs:
      - name: pr
        resource: pull-request
    params:
    - name: status
      value: "pending" 

I created runs with:

tkn pipeline start git-admission-control

I created these PipelineResources:

apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
  name: repro-git-pr
  namespace: default
spec:
  params:
  - name: url
    value: https://github.com/bobcatfish/tekton-lab
  - name: revision
    value: pr_status_update
  type: git
---
apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
  name: repro-pr-pr
  namespace: default
spec:
  params:
  - name: url
    value: https://github.com/bobcatfish/tekton-lab/pull/4
  secrets:
  - fieldName: githubToken
    secretKey: token
    secretName: webhook-secret
  type: pullRequest

(webhook-secret has the expected secretKey and fieldName; I don't think this is relevant b/c the error didn't seem to have anything do with permissions, and was able to be used to fetch info at least)

(bobcatfish/tekton-lab#4)

Additional Info

Before we genearlized the pullrequest resource (i think to support gitlab?) I was able to successfull use this version of the resource: https://github.com/bobcatfish/catservice/blob/master/tekton/set-status.yaml

I was surprised to see that the format of the status file changed completely so I might still be missing a similar detail? I was only able to figure out the previous syntax didn't work after looking at the examples in https://github.com/tektoncd/pipeline/tree/master/cmd/pullrequest-init/example/status

@vdemeester
Copy link
Member

/kind bug

@tekton-robot tekton-robot added the kind/bug Categorizes issue or PR as related to a bug. label Dec 20, 2019
@wlynch
Copy link
Member

wlynch commented Jan 7, 2020

I'm fairly sure this was caused by GitHub returning 404 in cases where the auth token isn't valid.

For example:

API request with no auth:

$ curl -X POST https://api.github.com/repos/wlynch/test/statuses/9bcde245572c74329827acdcab88792ebb84d578
{
  "message": "Not Found",
  "documentation_url": "https://developer.github.com/v3/repos/statuses/#create-a-status"
}

API request with auth:

$ curl -H "Authorization: token $GITHUB_TOKEN" -X POST https://api.github.com/repos/wlynch/test/statuses/9bcde245572c74329827acdcab88792ebb84d578
{
  "message": "Validation Failed",
  "errors": [
    {
      "resource": "Status",
      "code": "custom",
      "field": "state",
      "message": "state is not included in the list"
    }
  ],
  "documentation_url": "https://developer.github.com/v3/repos/statuses/#create-a-status"
}

Unfortunately I'm not sure there's much we can do here, since we're just returning the error we got back from GitHub.

Can you sanity check that the token is valid? Keep in mind that if webhook-secret is in fact the webhook secret token this is not the same as an API access token.

@bobcatfish
Copy link
Collaborator Author

Thanks @wlynch !! That helps a lot - I was able to use curl and my token and I saw the same "Validation Failed" error that you saw so the token I was trying to use was good but it turns out I was using it wrong - I didn't realize that in #1550 the secret fieldName changed from githubToken to authToken 😅 🤦‍♀️ The docs were even correct but it was so hard to see (shoutout to the time that @imjasonh helped me see that I wasn't able to use my secret b/c it was called webook_secret instead of webhook_secret)

Anyway so now with the below PipelineResource instead of the one above, I was finally able to update the status on my PR!!!! 🎉

apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
  name: repro-pr-pr
  namespace: default
spec:
  params:
  - name: url
    value: https://github.com/bobcatfish/tekton-lab/pull/4
  secrets:
  - fieldName: authToken
    secretKey: token
    secretName: webhook-secret
  type: pullRequest

So there was no bug after all and the PullRequest resource DOES work in 0.9.2 🎉🎉🎉 phew!!!

I'm gonna close this and open another issue about how we can improve the debugging experience (like you said it's hard when it's GitHub giving us the 404!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

4 participants