-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
203 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { Command } from "types"; | ||
import HelpCommand from "./help" | ||
import HelpCommand from "./help"; | ||
import PTALCommand from "./ptal"; | ||
|
||
const commands: Command[] = [ | ||
HelpCommand | ||
HelpCommand, | ||
PTALCommand | ||
]; | ||
|
||
export default commands; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { Command } from "types"; | ||
import {EmbedBuilder, SlashCommandBuilder} from "@discordjs/builders"; | ||
import { Octokit } from "@octokit/rest"; | ||
|
||
const command = { | ||
data: new SlashCommandBuilder() | ||
.setName("ptal") | ||
.setDescription('Open a Please Take a Look (PTAL) request') | ||
.addStringOption((option) => | ||
option.setName('github').setDescription('A link to a GitHub pull request').setRequired(true) | ||
) | ||
.addStringOption((option) => | ||
option.setName('description').setDescription('A short description of the PTAL request').setRequired(true) | ||
) | ||
.addStringOption((option) => | ||
option.setName('deployment').setDescription('A link to a (preview) deployment related to the PTAL').setRequired(false) | ||
) | ||
.addStringOption((option) => | ||
option.setName('other').setDescription('Other links related to the PTAL, comma seperated').setRequired(false) | ||
), | ||
async execute(interaction) { | ||
|
||
const github = interaction.options.getString("github"); | ||
if(!github) | ||
{ | ||
return interaction.error("github option required, but not found"); | ||
} | ||
const description = interaction.options.getString("description"); | ||
if(!description) | ||
{ | ||
return interaction.error("github option required, but not found"); | ||
} | ||
const deployment = interaction.options.getString("deployment"); | ||
let deploymentURL: URL | undefined; | ||
if(deployment) | ||
{ | ||
try | ||
{ | ||
deploymentURL = new URL(deployment); | ||
} | ||
catch | ||
{ | ||
return interaction.warning("Failed to parse the deployment url. Are you sure it was in the correct format? Please sure they start with a valid protocol."); | ||
} | ||
} | ||
const other = interaction.options.getString("other"); | ||
let otherURLs: URL[] = []; | ||
if(other) | ||
{ | ||
let urls = other.split(","); | ||
|
||
urls.forEach(url => { | ||
try | ||
{ | ||
const parsedURL = new URL(url.trim()); | ||
|
||
otherURLs.push(parsedURL); | ||
} | ||
catch | ||
{ | ||
return interaction.warning(`Failed to parse the other urls (specifically: ${url}). Are you sure it they were all in the correct format? Please sure they start with a valid protocol.`); | ||
} | ||
}) | ||
} | ||
|
||
const octokit: Octokit = new Octokit(); | ||
|
||
const githubRE = | ||
/((https:\/\/)?github\.com\/)?(?<ORGANISATION>[^\/]+)\/(?<REPOSITORY>[^\/]+)\/pull\/(?<NUMBER>\d+)/; | ||
const otherRE = /((?<ORGANISATION>[^\/]+)\/)?(?<REPOSITORY>[^(#|\s|\/)]+)(#)(?<NUMBER>\d+)/; | ||
|
||
const match = github.match(githubRE) || github.match(otherRE); | ||
if (!match) { | ||
return interaction.warning("The github PR entered wasn't in a supported format. For help with the format, use /help"); | ||
} | ||
|
||
let groups = match.groups!; | ||
|
||
const pr_info = { | ||
owner: groups['ORGANISATION'], | ||
repo: groups['REPOSITORY'], | ||
pull_number: parseInt(groups['NUMBER']), | ||
}; | ||
|
||
let pr: Awaited<ReturnType<typeof octokit.rest.pulls.get>>; | ||
|
||
try | ||
{ | ||
pr = await octokit.rest.pulls.get(pr_info); | ||
} | ||
catch(err) | ||
{ | ||
interaction.error("Failed to request pull request from the github api"); | ||
} | ||
|
||
return interaction.deferReply({hidden: false}, async () => { | ||
|
||
|
||
}); | ||
}, | ||
} satisfies Command; | ||
|
||
export default command; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters