This repository has been archived by the owner on Sep 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ubiquity:development' into dev-6
- Loading branch information
Showing
15 changed files
with
221 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ export enum IssueCommentCommands { | |
|
||
ALLOW = "/allow", | ||
AUTOPAY = "/autopay", | ||
AUTHORIZE = "/authorize", | ||
} |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { _approveLabelChange, getLabelChanges } from "../../../adapters/supabase"; | ||
import { getBotContext, getLogger } from "../../../bindings"; | ||
import { getUserPermission } from "../../../helpers"; | ||
import { Payload } from "../../../types"; | ||
import { ErrorDiff } from "../../../utils/helpers"; | ||
import { bountyInfo } from "../../wildcard"; | ||
|
||
export const approveLabelChange = async () => { | ||
const context = getBotContext(); | ||
const logger = getLogger(); | ||
const payload = context.payload as Payload; | ||
const sender = payload.sender.login; | ||
|
||
logger.info(`Received '/authorize' command from user: ${sender}`); | ||
|
||
const { issue, repository } = payload; | ||
if (!issue) { | ||
logger.info(`Skipping '/authorize' because of no issue instance`); | ||
return; | ||
} | ||
|
||
// check if sender is admin | ||
// passing in context so we don't have to make another request to get the user | ||
const permissionLevel = await getUserPermission(sender, context); | ||
|
||
// if sender is not admin, return | ||
if (permissionLevel !== "admin" && permissionLevel !== "billing_manager") { | ||
logger.info(`User ${sender} is not an admin/billing_manager`); | ||
return ErrorDiff(`You are not an admin/billing_manager and do not have the required permissions to access this function.`); | ||
} | ||
|
||
const issueDetailed = bountyInfo(issue); | ||
|
||
if (!issueDetailed.priceLabel || !issueDetailed.priorityLabel || !issueDetailed.timelabel) { | ||
logger.info(`Skipping... its not a bounty`); | ||
return ErrorDiff(`No valid bounty label on this issue`); | ||
} | ||
|
||
// check for label altering here | ||
const labelChanges = await getLabelChanges(repository.full_name, [issueDetailed.priceLabel, issueDetailed.priorityLabel, issueDetailed.timelabel]); | ||
|
||
await _approveLabelChange(labelChanges.id); | ||
|
||
return `Label change has been approved, permit can now be generated`; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { saveLabelChange } from "../../adapters/supabase"; | ||
import { getBotContext, getLogger } from "../../bindings"; | ||
import { hasLabelEditPermission } from "../../helpers"; | ||
import { Payload } from "../../types"; | ||
|
||
export const watchLabelChange = async () => { | ||
const logger = getLogger(); | ||
const context = getBotContext(); | ||
|
||
const payload = context.payload as Payload; | ||
|
||
const { repository, label, changes, sender } = payload; | ||
|
||
const { full_name } = repository; | ||
|
||
const previousLabel = changes?.name.from; | ||
const currentLabel = label?.name; | ||
const triggerUser = sender.login; | ||
|
||
if (!previousLabel || !currentLabel) { | ||
logger.debug("watchLabelChange: No label name change.. skipping"); | ||
return; | ||
} | ||
|
||
// check if user is authorized to make the change | ||
const hasAccess = await hasLabelEditPermission(currentLabel, triggerUser, repository.full_name); | ||
|
||
await saveLabelChange(triggerUser, full_name, previousLabel, currentLabel, hasAccess); | ||
logger.debug("watchLabelChange: label name change saved to db"); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CREATE TABLE IF NOT EXISTS label_changes ( | ||
id serial PRIMARY KEY, | ||
created timestamptz NOT NULL, | ||
updated timestamptz NOT NULL, | ||
username text NOT NULL, | ||
repository text NOT NULL, | ||
label_from text NOT NULL, | ||
label_to text NOT NULL, | ||
authorized boolean NOT NULL | ||
); |
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 @@ | ||
ALTER TABLE label_changes ENABLE ROW LEVEL SECURITY |