-
Notifications
You must be signed in to change notification settings - Fork 46
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
Properly extract commit sha from PullRequests #186
Conversation
@philsturgeon @XVincentX |
One can check the proposed behavior of that branch in protect-earth/protect.earth#62 |
This gives a chance for feedback when pull requests are opened from a fork. In that case, the token is not granted with enough rights to create annotations in the upstream repository.
|
@@ -16,18 +23,33 @@ type Event = { | |||
|
|||
export const createOctokitInstance = (token: string) => TE.fromEither(E.tryCatch(() => new GitHub(token), E.toError)); | |||
|
|||
const tryCreateGithubCheck = async ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@XVincentX Could you please help me rewrite this in a more fp-ts way? I haven't found the proper way to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You really can't, since the underlying API has side-effects. You can wrap it (as you're doing) with tryCatch
later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a look and unfortunately I think it's going in the wrong direction regards the usage of fp-ts. Also, bundling so many changes together didn't really help the review.
I would suggest to close this, open a new PR fixing exclusively the bug. In meantime I can try to look at this during the weekend and cleanup some of the stuff.
To give you some context, this was born as a personal pet project to experiment functional concepts that "escalated" to be then the official action linter.
}) | ||
) | ||
); | ||
const spectralRuns = parsed.map(v => pipe(runSpectral(spectral, v))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're running only a single operation, you do not need to pipe
const spectralRuns = parsed.map(v => pipe(runSpectral(spectral, v))); | |
const spectralRuns = parsed.map(v => runSpectral(spectral, v)); |
pipe( | ||
getRepositoryInfoFromEvent(GITHUB_EVENT_PATH, INPUT_EVENT_NAME), | ||
TE.map(event => ({ event })) | ||
), | ||
TE.chain(({ event }) => | ||
pipe( | ||
readFilesToAnalyze(INPUT_FILE_GLOB, GITHUB_WORKSPACE), | ||
TE.chain(fileContents => createSpectralAnnotations(INPUT_SPECTRAL_RULESET, fileContents, GITHUB_WORKSPACE)), | ||
TE.map(annotations => ({ event, annotations })) | ||
) | ||
), | ||
TE.chain(({ event, annotations }) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I'd say this is going in the wrong direction. I'll probably have to check this out.
@@ -16,18 +23,33 @@ type Event = { | |||
|
|||
export const createOctokitInstance = (token: string) => TE.fromEither(E.tryCatch(() => new GitHub(token), E.toError)); | |||
|
|||
const tryCreateGithubCheck = async ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You really can't, since the underlying API has side-effects. You can wrap it (as you're doing) with tryCatch
later
return event.after; | ||
default: | ||
warning(event); | ||
throw new Error(`Unsupported event '${eventName}'`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the idea of fp-ts is not to throw exception, so this is not ok. This should return an Either and a Left instance when something goes wrong.
Done with #187
Ok. I'll learn by reading your code, then. From a usage standpoint, the two most important features that this PR tried to add were:
Bonus features (for potential later troubleshooting):
|
Fix an issue discovered by @philsturgeon in https://github.com/protect-earth/protect.earth/pull/61/checks?check_run_id=634958740
Also: