forked from ubiquity-os-marketplace/daemon-pricing
-
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.
Merge pull request ubiquity-os-marketplace#42 from gentlementlegen/fe…
…at/label-gating feat/label-gating
- Loading branch information
Showing
21 changed files
with
447 additions
and
133 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 |
---|---|---|
@@ -1,16 +1,9 @@ | ||
name: "Delegate Compute" | ||
description: "UbiquityOS Delegated Compute Action" | ||
outputs: | ||
result: # id of output | ||
result: | ||
description: "The result of a event handler" | ||
value: ${{ steps.mainHandler.outputs.result }} | ||
runs: | ||
using: "composite" | ||
steps: | ||
- run: cd ${{ github.action_path }} | ||
shell: bash | ||
- run: bun install | ||
shell: bash | ||
- run: bun start | ||
shell: bash | ||
id: mainHandler | ||
using: "node20" | ||
main: "dist/index.js" |
Large diffs are not rendered by default.
Oops, something went wrong.
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,62 @@ | ||
import { ContextPlugin } from "../types/plugin-input"; | ||
import { isPushEvent } from "../types/typeguards"; | ||
|
||
export async function getLabelsChanges(context: ContextPlugin) { | ||
if (!isPushEvent(context)) { | ||
context.logger.debug("Not a push event"); | ||
return false; | ||
} | ||
const { | ||
logger, | ||
payload: { repository, head_commit: headCommit }, | ||
} = context; | ||
const commitSha = headCommit?.id; | ||
let commitData; | ||
|
||
if (!commitSha) { | ||
throw new Error("No commit sha found"); | ||
} | ||
const owner = repository.owner?.login; | ||
|
||
if (!owner) { | ||
throw logger.error("No owner found in the repository"); | ||
} | ||
|
||
try { | ||
commitData = await context.octokit.rest.repos.getCommit({ | ||
owner, | ||
repo: repository.name, | ||
ref: commitSha, | ||
mediaType: { | ||
format: "diff", | ||
}, | ||
}); | ||
} catch (err: unknown) { | ||
logger.debug("Commit sha error.", { err }); | ||
} | ||
|
||
if (!commitData) { | ||
throw new Error("No commit data found"); | ||
} | ||
|
||
const data = commitData.data as unknown as string; | ||
const changes = data.split("\n"); | ||
|
||
const newLabelsRegex = /\+\s*collaboratorOnly:\s*(\S+)/; | ||
const oldLabelsRegex = /-\s*collaboratorOnly:\s*(\S+)/; | ||
|
||
const newLabels = extractLabels(changes, newLabelsRegex); | ||
const previousLabels = extractLabels(changes, oldLabelsRegex); | ||
|
||
if (!previousLabels && !newLabels) { | ||
logger.error("No label changes found in the diff"); | ||
} | ||
|
||
return !!previousLabels?.length || !!newLabels?.length; | ||
} | ||
|
||
function extractLabels(changes: string[], regex: RegExp): string | undefined { | ||
const matchedLine = changes?.find((line) => regex.test(line)); | ||
const match = matchedLine?.match(regex); | ||
return match ? match[1] : undefined; | ||
} |
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.