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.
- Loading branch information
Showing
7 changed files
with
126 additions
and
43 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { GitHubContext } from "../github-context"; | ||
|
||
export async function repositoryDispatch(event: GitHubContext<"repository_dispatch">) { | ||
console.log("Repository dispatch event received", event.payload); | ||
} |
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,41 @@ | ||
import { customOctokit } from "../github-client"; | ||
import { GitHubContext } from "../github-context"; | ||
|
||
interface WorkflowDispatchOptions { | ||
owner: string; | ||
repository: string; | ||
workflowId: string; | ||
ref?: string; | ||
inputs?: { [key: string]: string }; | ||
} | ||
|
||
async function getInstallationOctokitForOrg(context: GitHubContext, owner: string): Promise<InstanceType<typeof customOctokit>> { | ||
const installations = await context.octokit.apps.listInstallations(); | ||
const installation = installations.data.find((inst) => inst.account?.login === owner); | ||
|
||
if (!installation) { | ||
throw new Error(`No installation found for owner: ${owner}`); | ||
} | ||
|
||
return context.eventHandler.getAuthenticatedOctokit(installation.id); | ||
} | ||
|
||
export async function dispatchWorkflow(context: GitHubContext, options: WorkflowDispatchOptions) { | ||
const authenticatedOctokit = await getInstallationOctokitForOrg(context, options.owner); | ||
|
||
return await authenticatedOctokit.actions.createWorkflowDispatch({ | ||
owner: options.owner, | ||
repo: options.repository, | ||
workflow_id: options.workflowId, | ||
ref: options.ref ?? (await getDefaultBranch(context, options.owner, options.repository)), | ||
inputs: options.inputs, | ||
}); | ||
} | ||
|
||
async function getDefaultBranch(context: GitHubContext, owner: string, repository: string) { | ||
const repo = await context.octokit.repos.get({ | ||
owner: owner, | ||
repo: repository, | ||
}); | ||
return repo.data.default_branch; | ||
} |