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 other options to enter pr #55

Merged
merged 8 commits into from
Nov 15, 2023
Merged

Conversation

mandar1jn
Copy link
Collaborator

Parsing now supports:
https://github.com/withastro/houston-bot/pull/52
withastro/houston-bot#52
houston-bot#52

Also resolves a crash when an invalid deployment or other URL is provided

@mandar1jn mandar1jn requested a review from natemoo-re November 10, 2023 17:01
@mandar1jn
Copy link
Collaborator Author

I could have made the regex patterns a single pattern, but it became extremely hard to read so I kept them seperate

@mandar1jn mandar1jn mentioned this pull request Nov 10, 2023
pathSections.shift();
if(githubURL.hostname != "github.com" || pathSections.length != 4 || pathSections[2] != "pull" || !Number.parseInt(pathSections[3]))
const githubRE = /https:\/\/github\.com\/(?<ORGANISATION>[^\/]+)\/(?<REPOSITORY>[^\/]+)\/pull\/(?<NUMBER>\d+)/;
const otherRE = /((?<ORGANISATION>[^\/]+)\/)?(?<REPOSITORY>[^(#|\s)]+)(#|\s)(?<NUMBER>\d+)/;
Copy link

Choose a reason for hiding this comment

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

In the second regex, it may be worth to also match /<org?>/<repo?>/pull/<number> as well, because currently the options are either a full URL or /<org?>/<repo?>#<number>
The latter doesn't actually resolve in github (except #<number> inline, but that only works for a single repo)

Copy link

Choose a reason for hiding this comment

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

Also /org/repo/ 123 is valid because of (#|\s), I don't think that was intentional but feel free to correct me if I'm wrong

image

Copy link
Collaborator Author

@mandar1jn mandar1jn Nov 15, 2023

Choose a reason for hiding this comment

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

I had made both "https://" and "https:/​/github.com/" optional so that should work now. I have removed the optional whitespace between the number and the repo. No clue why I added that

repo,
pull_number
owner: groups["ORGANISATION"] ?? "withastro",
repo: groups["REPOSITORY"],
Copy link

Choose a reason for hiding this comment

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

No default repository, but it is optional in otherRE

(Is it meant to be optional in otherRE? I would have expected for #123 to resolve to withastro/astro/pulls/123 but maybe that was not the intention?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don’t believe it’s optional in otherRE

Copy link

Choose a reason for hiding this comment

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

I see, / 123 and similar matched the regex so I thought maybe it was meant to be, but looking again that is most likely not intentional.

Copy link

Choose a reason for hiding this comment

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

In that case it could be quite handy to add a list of allowed "syntaxes" to the bot message

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see, / 123 and similar matched the regex so I thought maybe it was meant to be, but looking again that is most likely not intentional.

Yeah. I’m guessing that it matches the repo name as “/“ in that case

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My comment on the other review also addresses this issue

@Tc-001
Copy link

Tc-001 commented Nov 13, 2023

With those few regex tweaks otherwise LGTM

Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

This LGTM!

Not blocking, but I found the nested if((match = githubOption.match(githubRE)) == null) quite difficult to read. Suggested a simplification that makes the logic easier to follow.

src/commands/ptal.ts Outdated Show resolved Hide resolved
src/commands/ptal.ts Outdated Show resolved Hide resolved
src/commands/ptal.ts Outdated Show resolved Hide resolved
@mandar1jn mandar1jn merged commit 9146611 into main Nov 15, 2023
1 check passed
@mandar1jn mandar1jn deleted the mandar1jn/ptal-easier-option branch November 15, 2023 16:39
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.

3 participants