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

Allow closing pull request instead of exiting with error #1065

Merged
merged 8 commits into from
Dec 29, 2024

Conversation

HasanHajHasan
Copy link
Contributor

Adding close PR feature as an option instead of failing it

Copy link
Owner

@xalvarez xalvarez left a comment

Choose a reason for hiding this comment

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

Hello @HasanHajHasan,

Thank you for your contribution!

I added some comments to your PR. It would be great if you could address them. If you need help with the adjustments, let me know and I can take over.

@@ -6,7 +6,7 @@ export interface IFile {
status: string
}

export default class GitHubService {
export default class GithubService {
Copy link
Owner

Choose a reason for hiding this comment

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

Would you mind not renaming this class?

src/main.ts Outdated
@@ -19,17 +19,25 @@ export async function run(): Promise<void> {
)
}
const githubToken: string = core.getInput('githubToken', {required: true})
const gitHubService = new GitHubService(githubToken)
const githubService = new GithubService(githubToken)
Copy link
Owner

Choose a reason for hiding this comment

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

Would you mind not renaming this variable?

Comment on lines 28 to 33
const response = await octokit.rest.pulls.update({
owner,
repo,
pull_number: pullRequestNumber,
state: 'closed'
})
Copy link
Owner

Choose a reason for hiding this comment

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

There's a GitHubService class which is responsible for interacting with GitHub. Adding this call here mixes responsibilities. I think a cleaner code would be:

if (closePR) {
        await githubService.closePullRequest(owner, repo, pullRequestNumber)
      } else {
        core.setFailed(`There is at least one file matching the pattern ${pattern}`)
      }

Additionally, the tests for this API call are missing, which is way the PR check is failing (coverage threshold isn't reached).

@@ -17,7 +22,20 @@ export async function checkChangedFilesAgainstPattern(
})

if (shouldPreventFileChange) {
core.setFailed(`There is at least one file matching the pattern ${pattern}`)
const closePR: boolean = core.getInput('closePR') === 'true'
Copy link
Owner

Choose a reason for hiding this comment

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

All inputs are read in main.ts. For consistency I would read this there too.

@HasanHajHasan
Copy link
Contributor Author

Hey @xalvarez,
Is there any missing or incomplete step|(s) needed to be done ? so we can proceed with the merge

@xalvarez
Copy link
Owner

Hi @HasanHajHasan, thanks for your changes! I'm currently on vacation and I can't properly review these changes right now. I'll take care of this PR as soon as I can.

@xalvarez xalvarez changed the title Feature/close pr Allow closing pull request instead of exiting with error Dec 29, 2024
Copy link
Owner

@xalvarez xalvarez left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution @HasanHajHasan! I'll merge these changes and prepare a release.

@xalvarez xalvarez merged commit 267c166 into xalvarez:main Dec 29, 2024
7 checks passed
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

Successfully merging this pull request may close these issues.

2 participants