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

Upgrading from 11.4.1 to 12.2.5 #1711

Closed
mimartin12 opened this issue Jul 8, 2022 · 8 comments
Closed

Upgrading from 11.4.1 to 12.2.5 #1711

mimartin12 opened this issue Jul 8, 2022 · 8 comments

Comments

@mimartin12
Copy link

mimartin12 commented Jul 8, 2022

Hey, I am having issues going from 11.4.1 to 12.2.5. When I upgrade, and I run npm install && npm run build I get the following.

src/comments.ts(81,33): error TS2339: Property 'repository' does not exist on type 'BranchProtectionRuleCreatedEvent | BranchProtectionRuleDeletedEvent | BranchProtectionRuleEditedEvent | ... 381 more ... | WorkflowDispatchEvent'.

Code:

const owner = context.payload.repository.owner.login;

Am I missing something that needs to be changed during an upgrade?

@welcome
Copy link

welcome bot commented Jul 8, 2022

Thanks for opening this issue. A contributor should be by to give feedback soon. In the meantime, please check out the contributing guidelines and explore other ways you can get involved.

@gr2m
Copy link
Contributor

gr2m commented Jul 8, 2022

try

const owner = context.payload.repository?.owner.login;

The .repository property is not guaranteed to exist on all events, but you should be fine if you have been thus far.

@mimartin12
Copy link
Author

I tried that, unfortunately same error.

src/comments.ts(81,33): error TS2339: Property 'repository' does not exist on type 'BranchProtectionRuleCreatedEvent | BranchProtectionRuleDeletedEvent | BranchProtectionRuleEditedEvent | ... 381 more ... | WorkflowDispatchEvent'.
  Property 'repository' does not exist on type 'never'.

@wolfy1339
Copy link
Collaborator

This should work for you

if ('repository' in context.payload) {
    // do stuff here
}

@mimartin12
Copy link
Author

This should work for you

if ('repository' in context.payload) {
    // do stuff here
}

That works, however, there would be a lot of if statements to check values for other expected values in context.payload. For example, I am getting errors for context.payload.number and context.payload.check_suite not existing. Has the structure of context.payload changed drastically in ProBot version 12?

@wolfy1339
Copy link
Collaborator

That works, however, there would be a lot of if statements to check values for other expected values in context.payload. For example, I am getting errors for context.payload.number and context.payload.check_suite not existing. Has the structure of context.payload changed drastically in ProBot version 12?

Yes, it has. We have upgraded to use @octokit/wehooks v9 in #1559

Instead of handling all the events in one handler, simply use one per event

app.on("pull_request", (context) => {
    // Do stuff here
    app.log.info(`Repo: ${context.repository}`);
});

@LeviDeng
Copy link

LeviDeng commented Nov 4, 2022

@mimartin12 you can use context.pullRequest() to get the owner

const params = context.pullRequest()
// Returns: {owner: 'username', repo: 'reponame', pull_number: 123}

https://probot.github.io/api/latest/classes/context.Context.html#pullRequest

Documentation for probot

@Uzlopak
Copy link
Collaborator

Uzlopak commented Nov 15, 2023

The solution is to write a typeguard.

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

5 participants