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

fix: don't fail when pull_request context in unavailable #207

Merged
merged 1 commit into from
Jul 22, 2024

Conversation

jamacku
Copy link
Member

@jamacku jamacku commented Jul 18, 2024

When running on non pull_request a target (e.g., repository_dispatch), don't fail and provide some meaningful output.

NOTE: Statuses and issue comments are not supported when using such triggers

Copy link

codecov bot commented Jul 18, 2024

Codecov Report

Attention: Patch coverage is 63.26531% with 18 lines in your changes missing coverage. Please review.

Project coverage is 86.69%. Comparing base (276e2a8) to head (ab46c3e).

Files Patch % Lines
src/main.ts 0.00% 10 Missing and 1 partial ⚠️
src/pull-request.ts 69.56% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #207      +/-   ##
==========================================
- Coverage   88.38%   86.69%   -1.70%     
==========================================
  Files          10       10              
  Lines         689      714      +25     
  Branches       73       83      +10     
==========================================
+ Hits          609      619      +10     
- Misses         78       93      +15     
  Partials        2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jamacku jamacku marked this pull request as draft July 18, 2024 13:12
Copy link
Member

@phracek phracek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, the conditaion pr.isInitilized() should be added also here:

await pr.setStatus(

@@ -16,7 +16,15 @@ let pr: PullRequest | undefined = undefined;
try {
const octokit = getOctokit(getInput('github_token', { required: true }));

pr = await PullRequest.initialize(context.issue.number, octokit);
if (!context.issue || !context.issue.number) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow this condition? Why we create a new Pull Request if it does not exist

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We create an "empty"/"uninitialized" Pull Request and pass it to the action and post function.

Pull Request object now provides a new method, isInitialized,, which returns a boolean and is used to determine if PR data is available. I think that this is cleaner then having everywhere if else conditions. Now it is in one place (PullRequest.isInitialized(): boolean)

When running on non pull_request like target (e.g. `repository_dispatch`) don't fail and provide some meaningful output.

NOTE: Statuses and issue comments are not supported when using such
triggers
@jamacku jamacku marked this pull request as ready for review July 19, 2024 13:21
@jamacku
Copy link
Member Author

jamacku commented Jul 19, 2024

I think that this PR should make Action more robust even if it doesn't fix the following issue:

@jamacku jamacku requested a review from phracek July 19, 2024 13:27
Copy link
Member

@phracek phracek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I did not hit any issue.

@jamacku jamacku merged commit f426e07 into sclorg:main Jul 22, 2024
5 of 7 checks passed
@jamacku jamacku deleted the dispatch branch July 22, 2024 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants