Skip to content

Commit d116c8b

Browse files
committed
Add action
1 parent eaf8791 commit d116c8b

File tree

5 files changed

+107
-0
lines changed

5 files changed

+107
-0
lines changed

Dockerfile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM python:3.7.3
2+
3+
LABEL maintainer="Peter Evans <[email protected]>"
4+
LABEL repository="https://github.com/peter-evans/create-issue-from-file"
5+
LABEL homepage="https://github.com/peter-evans/create-issue-from-file"
6+
7+
LABEL com.github.actions.name="Create Issue From File"
8+
LABEL com.github.actions.description="An action to create an issue using content from a file"
9+
LABEL com.github.actions.icon="alert-circle"
10+
LABEL com.github.actions.color="orange"
11+
12+
COPY LICENSE README.md /
13+
14+
COPY requirements.txt /tmp/
15+
RUN pip install --requirement /tmp/requirements.txt
16+
17+
COPY entrypoint.py /
18+
ENTRYPOINT [ "python", "./entrypoint.py" ]

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Peter Evans
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

entrypoint.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from github import Github
2+
from pathlib import Path
3+
import random
4+
import os
5+
6+
# Fetch required environment variables
7+
github_token = os.environ['GITHUB_TOKEN']
8+
github_repository = os.environ['GITHUB_REPOSITORY']
9+
issue_title = os.environ['ISSUE_TITLE']
10+
issue_content_path = os.environ['ISSUE_CONTENT_FILEPATH']
11+
12+
# Fetch optional environment variables
13+
issue_labels = os.environ.get('ISSUE_LABELS')
14+
issue_assignees = os.environ.get('ISSUE_ASSIGNEES')
15+
16+
# If the file does not exist there is no issue to create
17+
if not Path(issue_content_path).is_file():
18+
print("File not found")
19+
exit(0)
20+
21+
# Fetch the file content
22+
with open(issue_content_path, 'r') as f:
23+
issue_content = f.read()
24+
25+
# Fetch the repository object
26+
g = Github(github_token)
27+
# Split username/repository
28+
github_repository_parts = [l.strip() for l in github_repository.split('/')]
29+
repo = g.get_user().get_repo(github_repository_parts[1])
30+
# Create the issue
31+
issue = repo.create_issue(issue_title, issue_content)
32+
print("Created issue %d" % (issue.number))
33+
34+
if issue_labels is not None:
35+
# Split the labels input into a list
36+
labels_list = [l.strip() for l in issue_labels.split(',')]
37+
# Remove empty strings
38+
labels_list = list(filter(None, labels_list))
39+
# Apply labels to issue
40+
print("Applying labels")
41+
issue.edit(labels=labels_list)
42+
43+
if issue_assignees is not None:
44+
# Split the assignees input into a list
45+
assignees_list = [l.strip() for l in issue_assignees.split(',')]
46+
# Remove empty strings
47+
assignees_list = list(filter(None, assignees_list))
48+
# Assign issue
49+
print("Assigning issue to assignees")
50+
issue.edit(assignees=assignees_list)

example-content/output.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# title
2+
3+
An example issue created using content from [example-content/output.md](https://github.com/peter-evans/create-issue-from-file/blob/master/example-content/output.md)
4+
5+
## subtitle
6+
7+
Some text
8+
9+
- bullet points
10+
- bullet points
11+
12+
"quoted string"
13+
14+
```python
15+
s = "syntax highlighting"
16+
print(s)
17+
```

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PyGithub==1.43.7

0 commit comments

Comments
 (0)