- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
GitHub app actions improvements #14058
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 27 commits
995077e
              ed0e29b
              2e82e77
              2cab7ff
              a9cb28a
              9122939
              fa3baa6
              5e468d2
              cc12ab8
              b17eeac
              763bdeb
              225921b
              bf91b7c
              4163d3e
              2bf2abc
              2a6786a
              e02c8a1
              c93226b
              7a183e3
              84219aa
              53ba27e
              195f4cb
              72f7246
              ee80a7d
              6dfb780
              5ecffde
              6e41e47
              e0994c9
              962d622
              acee736
              abfd83d
              b88c1b5
              f689f33
              cce2b03
              c08842a
              7971ba9
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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, | ||
| })); | ||
| }, | ||
| }, | ||
| }; | ||
| 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)", | ||||||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo in description: Correct "Gihub" to "GitHub" There's a typo in the description property. "Gihub" should be corrected to "GitHub". Apply this diff to fix the typo: -description: "Create a new issue in a Gihub repo. [See the documentation](https://docs.github.com/en/rest/issues/issues#create-an-issue)",
+description: "Create a new issue in a GitHub repo. [See the documentation](https://docs.github.com/en/rest/issues/issues#create-an-issue)",Committable suggestion
 
        Suggested change
       
 | ||||||
| version: "0.3.0", | ||||||
| type: "action", | ||||||
| props: { | ||||||
| github, | ||||||
|  | @@ -13,6 +15,7 @@ export default { | |||||
| github, | ||||||
| "repoFullname", | ||||||
| ], | ||||||
| reloadProps: true, | ||||||
| }, | ||||||
| title: { | ||||||
| label: "Title", | ||||||
|  | @@ -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; | ||||||
| }, | ||||||
|  | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider refactoring common patterns in 'assignees' and 'labels' properties
The 'labels' property is structurally similar to the 'assignees' property, with the main difference being the API call and the mapped property. This similarity suggests an opportunity for refactoring to reduce code duplication.
Consider creating a higher-order function to generate these property objects. This could improve maintainability and reduce the chance of inconsistencies. Here's a potential refactor:
This refactoring would also make it easier to add new properties with similar structures in the future.