-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
1 parent
c4fb4dc
commit 87995b6
Showing
4 changed files
with
128 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Create Issue | ||
|
||
A very simple action to create an issue in a repository. | ||
|
||
Intended for internal use only. | ||
|
||
## Usage | ||
|
||
```yaml | ||
- uses: Homebrew/actions/create-issue@master | ||
with: | ||
token: ${{ github.token }} # defaults to this | ||
repository: ${{ github.repository }} # defaults to this | ||
title: Issue title | ||
body: Issue body | ||
labels: label1,label2 | ||
assignees: user1,user2 | ||
``` |
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,30 @@ | ||
name: Create issue | ||
description: Create an issue in a repository | ||
author: ZhongRuoyu | ||
branding: | ||
icon: alert-circle | ||
color: blue | ||
inputs: | ||
token: | ||
description: GitHub token | ||
required: false | ||
default: ${{github.token}} | ||
repository: | ||
description: Repository to send the issue to | ||
required: false | ||
default: ${{github.repository}} | ||
title: | ||
description: The title of the issue | ||
required: true | ||
body: | ||
description: The body of the issue | ||
required: true | ||
labels: | ||
description: Comma-separated list of labels to add to the issue | ||
required: false | ||
assignees: | ||
description: Comma-separated list of users to assign the issue to | ||
required: false | ||
runs: | ||
using: node20 | ||
main: main.mjs |
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,40 @@ | ||
import core from "@actions/core"; | ||
import github from "@actions/github"; | ||
|
||
async function main() { | ||
try { | ||
const token = core.getInput("token", { required: true }); | ||
const [owner, repo] = core.getInput("repository", { required: true }).split("/"); | ||
|
||
const title = core.getInput("title", { required: true }); | ||
const body = core.getInput("body", { required: true }); | ||
|
||
const labelsInput = core.getInput("labels"); | ||
const labels = labelsInput ? labelsInput.split(",") : []; | ||
const assigneesInput = core.getInput("assignees"); | ||
const assignees = assigneesInput ? assigneesInput.split(",") : []; | ||
|
||
const client = github.getOctokit(token); | ||
|
||
const response = await client.rest.issues.create({ | ||
owner, | ||
repo, | ||
title, | ||
body, | ||
labels, | ||
assignees, | ||
}); | ||
const issueNumber = response.data.number; | ||
const issueNodeId = response.data.node_id; | ||
const issueUrl = response.data.html_url; | ||
|
||
core.info(`Issue created: ${issueUrl}`); | ||
|
||
core.setOutput("number", issueNumber); | ||
core.setOutput("node_id", issueNodeId); | ||
} catch (error) { | ||
core.setFailed(error); | ||
} | ||
} | ||
|
||
await main(); |
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,40 @@ | ||
import util from "node:util"; | ||
|
||
test("create-issue", async () => { | ||
const mockPool = githubMockPool(); | ||
|
||
const token = "fake-token"; | ||
const title = "Issue title"; | ||
const body = "Issue body.\nLorem ipsum dolor sit amet."; | ||
const labels = "label1,label2"; | ||
const assignees = "assignee1,assignee2"; | ||
|
||
const issueNumber = 12345; | ||
|
||
mockInput("token", token); | ||
mockInput("repository", GITHUB_REPOSITORY); | ||
mockInput("title", title); | ||
mockInput("body", body); | ||
mockInput("labels", labels); | ||
mockInput("assignees", assignees); | ||
|
||
mockPool.intercept({ | ||
method: "POST", | ||
path: `/repos/${GITHUB_REPOSITORY}/issues`, | ||
headers: { | ||
Authorization: `token ${token}`, | ||
}, | ||
body: (htmlBody) => util.isDeepStrictEqual(JSON.parse(htmlBody), { | ||
title, | ||
body, | ||
labels: labels.split(","), | ||
assignees: assignees.split(","), | ||
}), | ||
}).defaultReplyHeaders({ | ||
"Content-Type": "application/json", | ||
}).reply(200, { | ||
number: issueNumber | ||
}); | ||
|
||
await loadMain(); | ||
}); |