generated from ubiquity/ts-template
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into feature/new-text-config-param-for-emp…
…ty-wallet
- Loading branch information
Showing
16 changed files
with
523 additions
and
195 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Delete Deployment | ||
|
||
on: | ||
delete: | ||
|
||
jobs: | ||
delete: | ||
runs-on: ubuntu-latest | ||
name: Delete Deployment | ||
steps: | ||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "20.10.0" | ||
|
||
- name: Enable corepack | ||
run: corepack enable | ||
|
||
- uses: actions/checkout@v4 | ||
|
||
- name: Get Deleted Branch Name | ||
id: get_branch | ||
run: | | ||
branch_name=$(echo '${{ github.event.ref }}' | sed 's#refs/heads/##' | sed 's#[^a-zA-Z0-9]#-#g') | ||
echo "branch_name=$branch_name" >> $GITHUB_ENV | ||
- name: Retrieve and Construct Full Worker Name | ||
id: construct_worker_name | ||
run: | | ||
base_name=$(grep '^name = ' wrangler.toml | sed 's/^name = "\(.*\)"$/\1/') | ||
full_worker_name="${base_name}-${{ env.branch_name }}" | ||
# Make sure that it doesnt exceed 63 characters or it will break RFC 1035 | ||
full_worker_name=$(echo "${full_worker_name}" | cut -c 1-63) | ||
echo "full_worker_name=$full_worker_name" >> $GITHUB_ENV | ||
- name: Delete Deployment with Wrangler | ||
uses: cloudflare/wrangler-action@v3 | ||
with: | ||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | ||
command: delete --name ${{ env.full_worker_name }} | ||
|
||
- name: Output Deletion Result | ||
run: | | ||
echo "### Deployment URL" >> $GITHUB_STEP_SUMMARY | ||
echo 'Deployment `${{ env.full_worker_name }}` has been deleted.' >> $GITHUB_STEP_SUMMARY |
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,92 @@ | ||
import { Context } from "../../types"; | ||
import { getOwnerRepoFromHtmlUrl } from "../../utils/issue"; | ||
|
||
async function getUserStopComments(context: Context, username: string): Promise<number> { | ||
const { payload, octokit, logger } = context; | ||
const { number, html_url } = payload.issue; | ||
const { owner, repo } = getOwnerRepoFromHtmlUrl(html_url); | ||
|
||
try { | ||
const comments = await octokit.paginate(octokit.issues.listComments, { | ||
owner, | ||
repo, | ||
issue_number: number, | ||
}); | ||
|
||
return comments.filter((comment) => comment.body?.includes("/stop") && comment.user?.login.toLowerCase() === username.toLowerCase()).length; | ||
} catch (error) { | ||
throw new Error(logger.error("Error while getting user stop comments", { error: error as Error }).logMessage.raw); | ||
} | ||
} | ||
|
||
export async function hasUserBeenUnassigned(context: Context, username: string): Promise<boolean> { | ||
const { | ||
env: { APP_ID }, | ||
} = context; | ||
const events = await getAssignmentEvents(context); | ||
const userAssignments = events.filter((event) => event.assignee === username); | ||
|
||
if (userAssignments.length === 0) { | ||
return false; | ||
} | ||
|
||
const unassignedEvents = userAssignments.filter((event) => event.event === "unassigned"); | ||
// all bot unassignments (/stop, disqualification, etc) | ||
// TODO: task-xp-guard: will also prevent future assignments so we need to add a comment tracker we can use here | ||
const botUnassigned = unassignedEvents.filter((event) => event.actorId === APP_ID); | ||
// UI assignment | ||
const adminUnassigned = unassignedEvents.filter((event) => event.actor !== username && event.actorId !== APP_ID); | ||
// UI assignment | ||
const userUnassigned = unassignedEvents.filter((event) => event.actor === username); | ||
const userStopComments = await getUserStopComments(context, username); | ||
/** | ||
* Basically the bot will be the actor in most cases but if we | ||
* remove the /stop usage which does not trigger future disqualification | ||
* then any other bot unassignment will be considered valid | ||
*/ | ||
|
||
const botMinusUserStopCommands = Math.max(0, botUnassigned.length - userStopComments); | ||
const userUiMinusUserStopCommands = Math.max(0, userUnassigned.length - userStopComments); | ||
|
||
return botMinusUserStopCommands > 0 || userUiMinusUserStopCommands > 0 || adminUnassigned.length > 0; | ||
} | ||
|
||
async function getAssignmentEvents(context: Context) { | ||
const { repository, issue } = context.payload; | ||
try { | ||
const data = await context.octokit.paginate(context.octokit.issues.listEventsForTimeline, { | ||
owner: repository.owner.login, | ||
repo: repository.name, | ||
issue_number: issue.number, | ||
}); | ||
|
||
const events = data | ||
.filter((event) => event.event === "assigned" || event.event === "unassigned") | ||
.map((event) => { | ||
let actor, assignee, createdAt, actorId; | ||
|
||
if ((event.event === "unassigned" || event.event === "assigned") && "actor" in event && event.actor && "assignee" in event && event.assignee) { | ||
actor = event.actor.login; | ||
assignee = event.assignee.login; | ||
createdAt = event.created_at; | ||
actorId = event.actor.id; | ||
} | ||
|
||
return { | ||
event: event.event, | ||
actor, | ||
actorId, | ||
assignee, | ||
createdAt, | ||
}; | ||
}); | ||
|
||
return events | ||
.filter((event) => event !== undefined) | ||
.sort((a, b) => { | ||
return new Date(a.createdAt || "").getTime() - new Date(b.createdAt || "").getTime(); | ||
}); | ||
} catch (error) { | ||
throw new Error(context.logger.error("Error while getting assignment events", { error: error as Error }).logMessage.raw); | ||
} | ||
} |
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
Oops, something went wrong.