Skip to content

Commit 66a361b

Browse files
committed
[Components] github #14859
Sources - New Workflow Run Completed (Instant) - New Run Job Completed (Instant) Actions - Create Workflow Dispatch - Enable Workflow - Disable Workflow - List Workflow Runs - Get Workflow Run
1 parent cb1f43b commit 66a361b

File tree

9 files changed

+424
-1
lines changed

9 files changed

+424
-1
lines changed

components/github/actions/common/constants.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const PULL_REQUEST_STATES = [
66
"PENDING",
77
];
88

9+
const LIMIT = 100;
10+
911
export default {
1012
PULL_REQUEST_STATES,
13+
LIMIT,
1114
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import github from "../../github.app.mjs";
3+
4+
export default {
5+
key: "github-create-workflow-dispatch",
6+
name: "Create Workflow Dispatch",
7+
description: "Creates a new workflow dispatch event. [See the documentation](https://docs.github.com/en/rest/actions/workflows?apiVersion=2022-11-28#create-a-workflow-dispatch-event)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
github,
12+
repoFullname: {
13+
propDefinition: [
14+
github,
15+
"repoFullname",
16+
],
17+
},
18+
workflowId: {
19+
propDefinition: [
20+
github,
21+
"workflowId",
22+
({ repoFullname }) => ({
23+
repoFullname,
24+
}),
25+
],
26+
},
27+
ref: {
28+
type: "string",
29+
label: "Ref",
30+
description: "The git reference for the workflow. The reference can be a branch or tag name.",
31+
},
32+
inputs: {
33+
type: "object",
34+
label: "Inputs",
35+
description: "Input keys and values configured in the workflow file. The maximum number of properties is 10. Any default properties configured in the workflow file will be used when inputs are omitted.",
36+
optional: true,
37+
},
38+
},
39+
async run({ $ }) {
40+
try {
41+
const response = await this.github.createWorkflowDispatch({
42+
repoFullname: this.repoFullname,
43+
workflowId: this.workflowId,
44+
data: {
45+
ref: this.ref,
46+
inputs: this.inputs,
47+
},
48+
});
49+
50+
$.export("$summary", "Workflow dispatch successfully created!");
51+
52+
return response;
53+
} catch (e) {
54+
throw new ConfigurationError(e?.response?.data?.message);
55+
}
56+
},
57+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import github from "../../github.app.mjs";
3+
4+
export default {
5+
key: "github-disable-workflow",
6+
name: "Disable Workflow",
7+
description: "Disables a workflow and sets the **state** of the workflow to **disabled_manually**. [See the documentation](https://docs.github.com/en/rest/actions/workflows?apiVersion=2022-11-28#disable-a-workflow)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
github,
12+
repoFullname: {
13+
propDefinition: [
14+
github,
15+
"repoFullname",
16+
],
17+
},
18+
workflowId: {
19+
propDefinition: [
20+
github,
21+
"workflowId",
22+
({ repoFullname }) => ({
23+
repoFullname,
24+
}),
25+
],
26+
},
27+
},
28+
async run({ $ }) {
29+
try {
30+
const response = await this.github.disableWorkflow({
31+
repoFullname: this.repoFullname,
32+
workflowId: this.workflowId,
33+
});
34+
35+
$.export("$summary", `Successfully disabled the workflow with Id: ${this.workflowId}!`);
36+
37+
return response;
38+
} catch (e) {
39+
throw new ConfigurationError(e?.response?.data?.message);
40+
}
41+
},
42+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import github from "../../github.app.mjs";
2+
3+
export default {
4+
key: "github-enable-workflow",
5+
name: "Enable Workflow",
6+
description: "Enables a workflow and sets the **state** of the workflow to **active**. [See the documentation](https://docs.github.com/en/rest/actions/workflows?apiVersion=2022-11-28#enable-a-workflow)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
github,
11+
repoFullname: {
12+
propDefinition: [
13+
github,
14+
"repoFullname",
15+
],
16+
},
17+
workflowId: {
18+
propDefinition: [
19+
github,
20+
"workflowId",
21+
({ repoFullname }) => ({
22+
repoFullname,
23+
}),
24+
],
25+
},
26+
},
27+
async run({ $ }) {
28+
const response = await this.github.enableWorkflow({
29+
repoFullname: this.repoFullname,
30+
workflowId: this.workflowId,
31+
});
32+
33+
$.export("$summary", `Successfully enabled the workflow with Id: ${this.workflowId}!`);
34+
35+
return response;
36+
},
37+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import github from "../../github.app.mjs";
2+
3+
export default {
4+
key: "github-get-workflow-run",
5+
name: "Get Workflow Run",
6+
description: "Gets a specific workflow run. [See the documentation](https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#get-a-workflow-run)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
github,
11+
repoFullname: {
12+
propDefinition: [
13+
github,
14+
"repoFullname",
15+
],
16+
},
17+
workflowRunId: {
18+
propDefinition: [
19+
github,
20+
"workflowRunId",
21+
({ repoFullname }) => ({
22+
repoFullname,
23+
}),
24+
],
25+
optional: true,
26+
},
27+
},
28+
async run({ $ }) {
29+
const response = await this.github.getWorkflowRun({
30+
repoFullname: this.repoFullname,
31+
workflowRunId: this.workflowRunId,
32+
});
33+
34+
$.export("$summary", `Successfully retrieved the workflow run with Id: ${this.workflowRunId}!.`);
35+
36+
return response;
37+
},
38+
};
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import github from "../../github.app.mjs";
2+
3+
export default {
4+
key: "github-list-workflow-runs",
5+
name: "List Workflow Runs",
6+
description: "List workflowRuns for a repository [See the documentation](https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#list-workflow-runs-for-a-repository)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
github,
11+
repoFullname: {
12+
propDefinition: [
13+
github,
14+
"repoFullname",
15+
],
16+
},
17+
limit: {
18+
type: "integer",
19+
label: "Limit",
20+
description: "The maximum quantity to be returned.",
21+
},
22+
},
23+
async run({ $ }) {
24+
let page = 1;
25+
const perPage = 100;
26+
let allWorkflowRuns = [];
27+
let count = 0;
28+
29+
while (true) {
30+
const { workflow_runs: workflowRuns } = await this.github.listWorkflowRuns({
31+
repoFullname: this.repoFullname,
32+
perPage: perPage,
33+
page: page,
34+
});
35+
36+
if ((workflowRuns.length === 0) || count >= this.limit) {
37+
break;
38+
}
39+
count += workflowRuns.length;
40+
41+
allWorkflowRuns = allWorkflowRuns.concat(workflowRuns);
42+
page += 1;
43+
}
44+
45+
$.export("$summary", `Successfully retrieved ${allWorkflowRuns.length} workflow runs.`);
46+
47+
return allWorkflowRuns;
48+
},
49+
};

components/github/github.app.mjs

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Octokit } from "@octokit/core";
22
import { paginateRest } from "@octokit/plugin-paginate-rest";
3-
import queries from "./common/queries.mjs";
43
import {
54
axios, ConfigurationError,
65
} from "@pipedream/platform";
6+
import constants from "./actions/common/constants.mjs";
77
import mutations from "./common/mutations.mjs";
8+
import queries from "./common/queries.mjs";
89

910
const CustomOctokit = Octokit.plugin(paginateRest);
1011

@@ -271,6 +272,48 @@ export default {
271272
}));
272273
},
273274
},
275+
workflowId: {
276+
type: "string",
277+
label: "Workflow Id",
278+
description: "The Id of the workflow.",
279+
async options({
280+
repoFullname, page,
281+
}) {
282+
const { workflows: items } = await this.listWorkflows({
283+
repoFullname,
284+
perPage: constants.LIMIT,
285+
page,
286+
});
287+
288+
return items.map(({
289+
id: value, name: label,
290+
}) => ({
291+
label,
292+
value,
293+
}));
294+
},
295+
},
296+
workflowRunId: {
297+
type: "string",
298+
label: "Workflow Run Id",
299+
description: "The Id of the workflow Run.",
300+
async options({
301+
repoFullname, page,
302+
}) {
303+
const { workflow_runs: items } = await this.listWorkflowRuns({
304+
repoFullname,
305+
perPage: constants.LIMIT,
306+
page,
307+
});
308+
309+
return items.map(({
310+
id: value, name: label,
311+
}) => ({
312+
label,
313+
value,
314+
}));
315+
},
316+
},
274317
},
275318
methods: {
276319
_baseApiUrl() {
@@ -685,6 +728,66 @@ export default {
685728

686729
return response.data;
687730
},
731+
async listWorkflows({
732+
repoFullname,
733+
perPage,
734+
page,
735+
}) {
736+
const response = await this._client().request(`GET /repos/${repoFullname}/actions/workflows`, {
737+
per_page: perPage,
738+
page: page,
739+
});
740+
741+
return response.data;
742+
},
743+
async listWorkflowRuns({
744+
repoFullname,
745+
perPage,
746+
page,
747+
}) {
748+
const response = await this._client().request(`GET /repos/${repoFullname}/actions/runs`, {
749+
per_page: perPage,
750+
page: page,
751+
});
752+
753+
return response.data;
754+
},
755+
async getWorkflowRun({
756+
repoFullname, workflowRunId,
757+
}) {
758+
const response = await this._client().request(`GET /repos/${repoFullname}/actions/runs/${workflowRunId}`);
759+
760+
return response.data;
761+
},
762+
createWorkflowDispatch({
763+
repoFullname,
764+
workflowId,
765+
...opts
766+
}) {
767+
return this._makeRequest({
768+
method: "POST",
769+
path: `/repos/${repoFullname}/actions/workflows/${workflowId}/dispatches`,
770+
...opts,
771+
});
772+
},
773+
disableWorkflow({
774+
repoFullname,
775+
workflowId,
776+
}) {
777+
return this._makeRequest({
778+
method: "PUT",
779+
path: `/repos/${repoFullname}/actions/workflows/${workflowId}/disable`,
780+
});
781+
},
782+
enableWorkflow({
783+
repoFullname,
784+
workflowId,
785+
}) {
786+
return this._makeRequest({
787+
method: "PUT",
788+
path: `/repos/${repoFullname}/actions/workflows/${workflowId}/enable`,
789+
});
790+
},
688791
async getUserRepoPermissions({
689792
repoFullname, username,
690793
}) {

0 commit comments

Comments
 (0)