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

star.<created|deleted> handler failing #2

Closed
oscard0m opened this issue Feb 26, 2023 · 23 comments
Closed

star.<created|deleted> handler failing #2

oscard0m opened this issue Feb 26, 2023 · 23 comments

Comments

@oscard0m
Copy link

I am opening this issue where we can comment on your usecase. I think we are adding noise to this already existing discussion in Probot's repo: probot/probot#1795

Your handler is doing 3 or 4 calls (depending on the conditionals) to GitHub's API:

  • context.octokit.issues.listForRepo
  • context.octokit.issues.create
  • context.octokit.users.getByUsername
  • context.octokit.issues.createComment

Can you validate which requests to the API are working and which one/s are giving you a 401? I think it's a good start to try to figure out this first of all.

@kaf-lamed-beyt
Copy link
Owner

This is a really good idea. Thank you so much!

My PC is currently low, and I may have to use my mobile phone to try and trigger the bot. So, my response may come in a bit late, and seem a little far-fetched

I'll be back shortly with the feedback

@kaf-lamed-beyt
Copy link
Owner

When I tried using the bot, by starring the repo it is installed on, since I don't have any way to verify which calls are being sent.

I have this error

AggregateError: 
    HttpError: Not found. May be due to lack of authentication. Reason: Handling a "star.created" event: an "installation" key is missing. The installation ID cannot be determined
        at /var/task/node_modules/@octokit/request/dist-node/index.js:86:21
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async Job.doExecute (/var/task/node_modules/bottleneck/light.js:405:18)

...and here's what is in the headers. I think the github signature headers too are missing, and I still haven't figured out why it like this. To fix this, sometime ago... I even tried installing and uninstalling the bot, nothing changed.

Cache-Control: public, max-age=0, must-revalidate
Content-Length: 441
Date: Sun, 26 Feb 2023 21:09:19 GMT
Server: Vercel
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
X-Vercel-Cache: MISS
X-Vercel-Id: iad1::iad1::vzdv8-1677445757568-185e06ffa020

@oscard0m
Copy link
Author

I suggest you modify your code to get some extra logs after each of the tasks performed by your event handler to see when is this Not found error happens. With the logs you shared it's not clear at what point is failing.

You can also debug your Probot app on your local machine, which makes it easier to get the details and debuggers to see how your code behaves. To test your app, you can simulate some events.

@kaf-lamed-beyt
Copy link
Owner

Okay, great! I'll try doing this, and take a look at the simulation of events.

But, I think the point where I run into an issue with testing it locally, is that when I run npm start it just opens a new webpage on port 3000. I have no idea how to actually debug or what to check since it is just rendering the default probot UI, since I'm deploying the bot with vercel serverless function

@oscard0m
Copy link
Author

Okay, great! I'll try doing this, and take a look at the simulation of events.

But, I think the point where I run into an issue with testing it locally, is that when I run npm start it just opens a new webpage on port 3000. I have no idea how to actually debug or what to check since it is just rendering the default probot UI, since I'm deploying the bot with vercel serverless function

Did you try following the steps in Probot's documentation? https://probot.github.io/docs/development/#running-the-app-locally

@kaf-lamed-beyt
Copy link
Owner

Sorry for cycling back late @oscard0m.

Yes, I've followed the steps in the robot documentation, but I kept getting a server error.

That's not the case though, as the problem is with the stars.created and .deleted webhook events. Anytime I perform these actions, I keep getting the authentication error.

I even went on to install the bot on a public repo, perhaps the reason why it wasn't working before as because it is installed on a private repository — still the same thing.

I even tried generating a new private key and changed my webhook secret. Nada.

@oscard0m
Copy link
Author

oscard0m commented Apr 2, 2023

Did you validate which of the calls to GitHub API is giving problems?:
#2 (comment)

I think it would be interesting to check that. Also, can you share which permissions your GitHub App have? https://docs.github.com/en/apps/maintaining-github-apps/editing-a-github-apps-permissions

@kaf-lamed-beyt
Copy link
Owner

Yes, I have checked the requests that are throwing errors, and it is the stars.created and star.deleted events.

image

...and the repository/app permission is only using the metadata scope since all it needs is the information about the repository it is installed on. But, I may be wrong though;

image

@oscard0m
Copy link
Author

oscard0m commented Apr 2, 2023

Yes, I have checked the requests that are throwing errors, and it is the stars.created and star.deleted events.

This means this handler is the one giving problems but inside this handler, which Request to GitHub API via Octokit is giving problems? Can you check that?

@kaf-lamed-beyt
Copy link
Owner

Oh! okay lemme do that now

@kaf-lamed-beyt
Copy link
Owner

Okay, I just realized that i can't test locally without running into some issues. But, when I push, and I check the webhook events that are fired, these events, below are where errors are coming from, and I can't exactly pin point with exact method of octokit is causing it.

app.on(["star.created", "star.deleted"], async (context) => {

@oscard0m
Copy link
Author

oscard0m commented Apr 2, 2023

Okay, I just realized that i can't test locally without running into some issues. But, when I push, and I check the webhook events that are fired, these events, below are where errors are coming from, and I can't exactly pin point with exact method of octokit is causing it.

app.on(["star.created", "star.deleted"], async (context) => {

Maybe you can try adding some to extra logs as I pointed in a past comment?

You can also try small steps:

  • Comment all the octokit interactions
  • Push that and assure everything works (no red event)
  • Uncomment the first interaction with octokit, push and check
  • Same for the others

@kaf-lamed-beyt
Copy link
Owner

Okay... I'll do that and come back with feedback.

Might take a while — perhaps in the afternoon. 🙏🙏

@kaf-lamed-beyt
Copy link
Owner

Ah! Great! These steps you added sounds great. I'll go through them.

@kaf-lamed-beyt
Copy link
Owner

Okay, so I tried the option you mentioned — by commenting all the octokit instances in the handler function. The authentication error below persisted, nonetheless 👇🏼

AggregateError: 
    HttpError: Not found. May be due to lack of authentication. Reason: Handling a "star.created" event: an "installation" key is missing. The installation ID cannot be determined
        at /var/task/node_modules/@octokit/request/dist-node/index.js:86:21
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async Job.doExecute (/var/task/node_modules/bottleneck/light.js:405:18)

One thing I noticed; whenever I star the repo, a "watch.started" webhook event is fired also — and it was succesful. Then, I thought "why not try the "watch.started" event".

When I did, I got the same auth error, but in this case, it was peculiar to the watch event. The funny thing now is that the "star.created" event fired successfully.

So now, I'm thinking the issue is from my probot installation — because, by default, I think probot handles the issue of authentication out-of-the-box for us, yeah?

I'll try setting up another probot app locally, if the is still persists, I'll reach out again.

@oscard0m
Copy link
Author

oscard0m commented Apr 2, 2023

Okay, so I tried the option you mentioned — by commenting all the octokit instances in the handler function. The authentication error below persisted, nonetheless 👇🏼

AggregateError: 
    HttpError: Not found. May be due to lack of authentication. Reason: Handling a "star.created" event: an "installation" key is missing. The installation ID cannot be determined
        at /var/task/node_modules/@octokit/request/dist-node/index.js:86:21
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async Job.doExecute (/var/task/node_modules/bottleneck/light.js:405:18)

One thing I noticed; whenever I star the repo, a "watch.started" webhook event is fired also — and it was succesful. Then, I thought "why not try the "watch.started" event".

When I did, I got the same auth error, but in this case, it was peculiar to the watch event. The funny thing now is that the "star.created" event fired successfully.

So now, I'm thinking the issue is from my probot installation — because, by default, I think probot handles the issue of authentication out-of-the-box for us, yeah?

I'll try setting up another probot app locally, if the is still persists, I'll reach out again.

With this said, I suspect the auth token you are using is not correct. Make sure you configured it correctly. More details here: https://probot.github.io/docs/configuration/

@kaf-lamed-beyt
Copy link
Owner

Oh oh! great! I'll have a look now.

@kaf-lamed-beyt
Copy link
Owner

I had a look at my env variables. and they are exactly as is, in the documentation;

image

Although I'm deploying my bot on Vercel, I've added all the variables in the environment variables route in my Vercel dashboard, except the WEBHOOK_PROXY_URL. Do I need to add it also?

@oscard0m
Copy link
Author

oscard0m commented Apr 2, 2023

So they are exactly the same as in your GitHub App settings?

@kaf-lamed-beyt
Copy link
Owner

Yes, actually.

@oscard0m
Copy link
Author

oscard0m commented Apr 2, 2023

Here you can find a version working: https://github.com/oscard0m/stargazer-test

I'm using the code but I had to use some adjustments. Using local development was quite easy to spot the issues.

I'm happy to schedule a session to pair-program on this and help you setup the local environment correctly and show you how to debug, etc.

Feel free to ask any question about my solutions

@oscard0m oscard0m closed this as completed Apr 2, 2023
@kaf-lamed-beyt
Copy link
Owner

Wohooo!!

Thank you so much. I'll have a look now.

@kaf-lamed-beyt
Copy link
Owner

When will you be free for a session and what exactly was the error 😭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants