Skip to content

Commit

Permalink
GitHub app actions improvements (PipedreamHQ#14058)
Browse files Browse the repository at this point in the history
* Create Issue adjustments + get push permission + improvements

* Create Issue + async props

* Get Repository improvements

* Search issues/prs improvements

* "Create or Update file contents" improvements

* Get Repository Contents adjustments

* Create Branch text adjustments

* Text updates

* Adding pagination to issues

* Update Issue adjustments

* Get Reviewers + adjustments

* List Gists and Update Gist updates

* Create Pull Request improvements

* Version bumps

* Version bumps

* Update components/github/actions/create-branch/create-branch.mjs

* Fix typos

* Fixing 'create or update file contents' branch prop

* Filtering out PRs from issueNumber prop

* Adjusting branch on 'Get Repository Content'

* Changing default review states to all

* Fixing 'list gists for user'

* Fix

* Improve reviewStates prop description

* Fixing syntax error in 'create or update file contents'

* Adjusting branch name syntax

* Fix: including branch when fetching file SHA

* Version bump

* Version bumps

---------

Co-authored-by: Leo Vu <[email protected]>
  • Loading branch information
GTFalcao and vunguyenhung authored Sep 28, 2024
1 parent d6d5192 commit d4c413b
Show file tree
Hide file tree
Showing 55 changed files with 381 additions and 314 deletions.
2 changes: 1 addition & 1 deletion components/easy_peasy_ai/easy_peasy_ai.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
60 changes: 60 additions & 0 deletions components/github/actions/common/asyncProps.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
export default {
assignees: {
label: "Assignees",
description: "One or more Users to assign to this issue",
type: "string[]",
optional: true,
options: async () => {
const collaborators = await this.github.getRepositoryCollaborators({
repoFullname: this.repoFullname,
});

return collaborators.map(({ login }) => login);
},
},
labels: {
label: "Labels",
description: "The label(s) to add to the issue",
type: "string[]",
optional: true,
options: async () => {
const labels = await this.github.getRepositoryLabels({
repoFullname: this.repoFullname,
});

return labels.map(({ name }) => name);
},
},
milestoneNumber: {
type: "integer",
label: "Milestone Number",
description: "The number of a milestone to associate the issue with",
optional: true,
options: async () => {
const items = await this.github.getRepositoryMilestones({
repoFullname: this.repoFullname,
});

return items.map((item) => ({
label: item.title,
value: +item.number,
}));
},
},
pullNumber: {
type: "integer",
label: "Pull Request Number",
description: "The pull request to get reviewers for",
options: async ({ page }) => {
const prs = await this.github.getRepositoryPullRequests({
page: page + 1,
repoFullname: this.repoFullname,
});

return prs.map((pr) => ({
label: pr.title,
value: +pr.number,
}));
},
},
};
8 changes: 4 additions & 4 deletions components/github/actions/create-branch/create-branch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import github from "../../github.app.mjs";
export default {
key: "github-create-branch",
name: "Create Branch",
description: "Create a new branch in a Github repo. [See docs here](https://docs.github.com/en/rest/git/refs?apiVersion=2022-11-28#create-a-reference)",
version: "0.0.12",
description: "Create a new branch in a Github repo. [See the documentation](https://docs.github.com/en/rest/git/refs?apiVersion=2022-11-28#create-a-reference)",
version: "0.0.13",
type: "action",
props: {
github,
Expand All @@ -17,12 +17,12 @@ export default {
},
branchName: {
label: "Branch Name",
description: "The name of the new branch that will be crated",
description: "The name of the new branch that will be created",
type: "string",
},
branchSha: {
label: "Source Branch",
description: "The source branch that will be used to create the new branch",
description: "The source branch that will be used to create the new branch. Defaults to the repository's default branch (usually `main` or `master`)",
propDefinition: [
github,
"branch",
Expand Down
4 changes: 2 additions & 2 deletions components/github/actions/create-gist/create-gist.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import utils from "../../actions/common/utils.mjs";
export default {
key: "github-create-gist",
name: "Create Gist",
description: "Allows you to add a new gist with one or more files. [See docs here](https://docs.github.com/en/rest/gists/gists?apiVersion=2022-11-28#create-a-gist)",
version: "0.0.6",
description: "Allows you to add a new gist with one or more files. [See the documentation](https://docs.github.com/en/rest/gists/gists?apiVersion=2022-11-28#create-a-gist)",
version: "0.0.7",
type: "action",
props: {
github,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import github from "../../github.app.mjs";
export default {
key: "github-create-issue-comment",
name: "Create Issue Comment",
description: "Create a new comment in a issue. [See docs here](https://docs.github.com/en/rest/issues/comments#create-an-issue-comment)",
version: "0.0.17",
description: "Create a new comment in a issue. [See the documentation](https://docs.github.com/en/rest/issues/comments#create-an-issue-comment)",
version: "0.0.18",
type: "action",
props: {
github,
Expand Down
69 changes: 33 additions & 36 deletions components/github/actions/create-issue/create-issue.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { checkPushPermission } from "../../common/utils.mjs";
import github from "../../github.app.mjs";
import asyncProps from "../common/asyncProps.mjs";

export default {
key: "github-create-issue",
name: "Create Issue",
description: "Create a new issue in a Gihub repo. [See docs here](https://docs.github.com/en/rest/issues/issues#create-an-issue)",
version: "0.2.16",
description: "Create a new issue in a Gihub repo. [See the documentation](https://docs.github.com/en/rest/issues/issues#create-an-issue)",
version: "0.3.0",
type: "action",
props: {
github,
Expand All @@ -13,6 +15,7 @@ export default {
github,
"repoFullname",
],
reloadProps: true,
},
title: {
label: "Title",
Expand All @@ -21,47 +24,41 @@ export default {
},
body: {
label: "Body",
description: "The contents of the issue",
description: "The text body of the issue",
type: "string",
optional: true,
},
labels: {
label: "Labels",
description: "Labels to associate with this issue. NOTE: Only users with push access can set labels for new issues",
optional: true,
propDefinition: [
github,
"labels",
(c) => ({
repoFullname: c.repoFullname,
}),
],
},
assignees: {
label: "Assignees",
description: "Logins for Users to assign to this issue. NOTE: Only users with push access can set assignees for new issues",
optional: true,
propDefinition: [
github,
"collaborators",
(c) => ({
repoFullname: c.repoFullname,
}),
],
},
},
methods: {
checkPushPermission,
},
async additionalProps() {
const canPush = await this.checkPushPermission();
return canPush
? {
assignees: asyncProps.assignees,
labels: asyncProps.labels,
milestoneNumber: asyncProps.milestoneNumber,
}
: {
infoBox: {
type: "alert",
alertType: "info",
content: "Labels, assignees and milestones can only be set by users with push access to the repository.",
},
};
},
async run({ $ }) {
const response = await this.github.createIssue({
repoFullname: this.repoFullname,
data: {
title: this.title,
body: this.body,
labels: this.labels,
assignees: this.assignees,
},
const { // eslint-disable-next-line no-unused-vars
github, repoFullname, infoBox, ...data
} = this;

const response = await github.createIssue({
repoFullname,
data,
});

$.export("$summary", "Successfully created issue.");
$.export("$summary", `Successfully created issue (ID: ${response.id})`);

return response;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import github from "../../github.app.mjs";

export default {
key: "github-create-or-update-file-contents",
name: "Create or update file contents",
description: "Create or update a file in a repository. This will replace an existing file. [See docs here](https://docs.github.com/en/rest/repos/contents#create-or-update-file-contents)",
version: "0.0.13",
name: "Create or Update File Contents",
description: "Create or update a file in a repository. [See the documentation](https://docs.github.com/en/rest/repos/contents#create-or-update-file-contents)",
version: "0.1.0",
type: "action",
props: {
github,
Expand Down Expand Up @@ -32,21 +32,25 @@ export default {
default: "Pipedream - {{steps.trigger.context.workflow_name}} ({{steps.trigger.context.workflow_id}})",
},
branch: {
label: "Branch",
propDefinition: [
github,
"branch",
(c) => ({
repoFullname: c.repoFullname,
}),
],
description:
"The branch name. Defaults to the repository’s default branch (usually `master`)",
type: "string",
"The branch to use. Defaults to the repository's default branch (usually `main` or `master`)",
optional: true,
},
},
async run({ $ }) {

const response = await this.github.createOrUpdateFileContent({
repoFullname: this.repoFullname,
path: this.path,
commitMessage: this.commitMessage,
fileContent: this.fileContent,
branch: this.branch,
const {
github, branch, ...data
} = this;
const response = await github.createOrUpdateFileContent({
...data,
branch: branch && branch.split("/")[1],
});

$.export("$summary", `Successfully set contents of ${this.path}${this.branch
Expand Down
Loading

0 comments on commit d4c413b

Please sign in to comment.