Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions components/github/actions/common/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const PULL_REQUEST_STATES = [
"PENDING",
];

const LIMIT = 100;

export default {
PULL_REQUEST_STATES,
LIMIT,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { ConfigurationError } from "@pipedream/platform";
import github from "../../github.app.mjs";

export default {
key: "github-create-workflow-dispatch",
name: "Create Workflow Dispatch",
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)",
version: "0.0.1",
type: "action",
props: {
github,
repoFullname: {
propDefinition: [
github,
"repoFullname",
],
},
workflowId: {
propDefinition: [
github,
"workflowId",
({ repoFullname }) => ({
repoFullname,
}),
],
},
ref: {
type: "string",
label: "Ref",
description: "The git reference for the workflow. The reference can be a branch or tag name.",
},
inputs: {
type: "object",
label: "Inputs",
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.",
optional: true,
},
},
async run({ $ }) {
try {
const response = await this.github.createWorkflowDispatch({
repoFullname: this.repoFullname,
workflowId: this.workflowId,
data: {
ref: this.ref,
inputs: this.inputs,
},
});

$.export("$summary", "Workflow dispatch successfully created!");

return response;
} catch (e) {
throw new ConfigurationError(e?.response?.data?.message);
}
},
};
42 changes: 42 additions & 0 deletions components/github/actions/disable-workflow/disable-workflow.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { ConfigurationError } from "@pipedream/platform";
import github from "../../github.app.mjs";

export default {
key: "github-disable-workflow",
name: "Disable Workflow",
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)",
version: "0.0.1",
type: "action",
props: {
github,
repoFullname: {
propDefinition: [
github,
"repoFullname",
],
},
workflowId: {
propDefinition: [
github,
"workflowId",
({ repoFullname }) => ({
repoFullname,
}),
],
},
},
async run({ $ }) {
try {
const response = await this.github.disableWorkflow({
repoFullname: this.repoFullname,
workflowId: this.workflowId,
});

$.export("$summary", `Successfully disabled the workflow with Id: ${this.workflowId}!`);

return response;
} catch (e) {
throw new ConfigurationError(e?.response?.data?.message);
}
},
};
37 changes: 37 additions & 0 deletions components/github/actions/enable-workflow/enable-workflow.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import github from "../../github.app.mjs";

export default {
key: "github-enable-workflow",
name: "Enable Workflow",
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)",
version: "0.0.1",
type: "action",
props: {
github,
repoFullname: {
propDefinition: [
github,
"repoFullname",
],
},
workflowId: {
propDefinition: [
github,
"workflowId",
({ repoFullname }) => ({
repoFullname,
}),
],
},
},
async run({ $ }) {
const response = await this.github.enableWorkflow({
repoFullname: this.repoFullname,
workflowId: this.workflowId,
});

$.export("$summary", `Successfully enabled the workflow with Id: ${this.workflowId}!`);

return response;
},
};
38 changes: 38 additions & 0 deletions components/github/actions/get-workflow-run/get-workflow-run.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import github from "../../github.app.mjs";

export default {
key: "github-get-workflow-run",
name: "Get Workflow Run",
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)",
version: "0.0.1",
type: "action",
props: {
github,
repoFullname: {
propDefinition: [
github,
"repoFullname",
],
},
workflowRunId: {
propDefinition: [
github,
"workflowRunId",
({ repoFullname }) => ({
repoFullname,
}),
],
optional: true,
},
},
async run({ $ }) {
const response = await this.github.getWorkflowRun({
repoFullname: this.repoFullname,
workflowRunId: this.workflowRunId,
});

$.export("$summary", `Successfully retrieved the workflow run with Id: ${this.workflowRunId}!.`);

return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import github from "../../github.app.mjs";

export default {
key: "github-list-workflow-runs",
name: "List Workflow Runs",
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)",
version: "0.0.1",
type: "action",
props: {
github,
repoFullname: {
propDefinition: [
github,
"repoFullname",
],
},
limit: {
type: "integer",
label: "Limit",
description: "The maximum quantity to be returned.",
},
},
async run({ $ }) {
let page = 1;
const perPage = 100;
let allWorkflowRuns = [];
let count = 0;

while (true) {
const { workflow_runs: workflowRuns } = await this.github.listWorkflowRuns({
repoFullname: this.repoFullname,
perPage: perPage,
page: page,
});

if ((workflowRuns.length === 0) || count >= this.limit) {
break;
}
count += workflowRuns.length;

allWorkflowRuns = allWorkflowRuns.concat(workflowRuns);
page += 1;
}

$.export("$summary", `Successfully retrieved ${allWorkflowRuns.length} workflow runs.`);

return allWorkflowRuns;
},
};
105 changes: 104 additions & 1 deletion components/github/github.app.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Octokit } from "@octokit/core";
import { paginateRest } from "@octokit/plugin-paginate-rest";
import queries from "./common/queries.mjs";
import {
axios, ConfigurationError,
} from "@pipedream/platform";
import constants from "./actions/common/constants.mjs";
import mutations from "./common/mutations.mjs";
import queries from "./common/queries.mjs";

const CustomOctokit = Octokit.plugin(paginateRest);

Expand Down Expand Up @@ -271,6 +272,48 @@ export default {
}));
},
},
workflowId: {
type: "string",
label: "Workflow Id",
description: "The Id of the workflow.",
async options({
repoFullname, page,
}) {
const { workflows: items } = await this.listWorkflows({
repoFullname,
perPage: constants.LIMIT,
page,
});

return items.map(({
id: value, name: label,
}) => ({
label,
value,
}));
},
},
workflowRunId: {
type: "string",
label: "Workflow Run Id",
description: "The Id of the workflow Run.",
async options({
repoFullname, page,
}) {
const { workflow_runs: items } = await this.listWorkflowRuns({
repoFullname,
perPage: constants.LIMIT,
page,
});

return items.map(({
id: value, name: label,
}) => ({
label,
value,
}));
},
},
},
methods: {
_baseApiUrl() {
Expand Down Expand Up @@ -685,6 +728,66 @@ export default {

return response.data;
},
async listWorkflows({
repoFullname,
perPage,
page,
}) {
const response = await this._client().request(`GET /repos/${repoFullname}/actions/workflows`, {
per_page: perPage,
page: page,
});

return response.data;
},
async listWorkflowRuns({
repoFullname,
perPage,
page,
}) {
const response = await this._client().request(`GET /repos/${repoFullname}/actions/runs`, {
per_page: perPage,
page: page,
});

return response.data;
},
async getWorkflowRun({
repoFullname, workflowRunId,
}) {
const response = await this._client().request(`GET /repos/${repoFullname}/actions/runs/${workflowRunId}`);

return response.data;
},
createWorkflowDispatch({
repoFullname,
workflowId,
...opts
}) {
return this._makeRequest({
method: "POST",
path: `/repos/${repoFullname}/actions/workflows/${workflowId}/dispatches`,
...opts,
});
},
disableWorkflow({
repoFullname,
workflowId,
}) {
return this._makeRequest({
method: "PUT",
path: `/repos/${repoFullname}/actions/workflows/${workflowId}/disable`,
});
},
enableWorkflow({
repoFullname,
workflowId,
}) {
return this._makeRequest({
method: "PUT",
path: `/repos/${repoFullname}/actions/workflows/${workflowId}/enable`,
});
},
async getUserRepoPermissions({
repoFullname, username,
}) {
Expand Down
Loading
Loading