Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dz0ny committed Feb 13, 2019
0 parents commit d6ec7a7
Show file tree
Hide file tree
Showing 15 changed files with 804 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
.pytest_cache
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.7.1
13 changes: 13 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"python.pythonPath": "/home/dz0ny/.local/share/virtualenvs/make-pr-9Hm3Atzw/bin/python",
"python.formatting.provider": "black",
"python.unitTest.pyTestArgs": [
"."
],
"python.unitTest.unittestEnabled": false,
"python.unitTest.nosetestsEnabled": false,
"python.unitTest.pyTestEnabled": true
}
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM python:3.7.2-alpine3.9

LABEL version="1.0.0"
LABEL repository="http://github.com/dz0ny/make-pr"
LABEL homepage="http://github.com/dz0ny/make-pr"
LABEL maintainer="Janez Troha"
LABEL "com.github.actions.name"="Automatic PR"
LABEL "com.github.actions.description"="Automatically creates PR"
LABEL "com.github.actions.icon"="git-pull-request"
LABEL "com.github.actions.color"="purple"

RUN apk --no-cache add jq bash
ADD requirements.txt /requirements.txt
RUN pip install -r /requirements.txt && rm -f /requirements.txt

ADD main.py /main.py
ADD entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Janez Troha

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
16 changes: 16 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
flake8 = "*"
black = "==18.9b0"
pytest = "*"

[packages]
requests = "*"
dacite = "*"

[requires]
python_version = "3.7"
182 changes: 182 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# GitHub action to automatically create PRs

## Installation

To configure the action simply add the following lines to your `.github/main.workflow` workflow file:

```
workflow "Automatic PR" {
on = "release"
resolves = "Create PR"
}
action "Create PR" {
uses = "dz0ny/create-pr:master"
args = "path/to/my/patch_recipe.py"
secrets = ["GITHUB_TOKEN"]
}
```

Contents of `path/to/my/patch_recipe.py:

```python
if __name__ == "__main__":
event = Event.fromPath(env["GITHUB_EVENT_PATH"])
if not event.is_release:
raise Exception("This event is not from release")

with commit(event, f"update_{event.release.tag_name}") as gh:
versions = gh.get("bin/runtime/versions")
versions.text: str = versions.text.replace("foo.bar", "def.bar")
gh.add(versions, "Update image to latest version")
gh.create_pr(
"Update image to latest version",
"This updates web image to the latest released version",
)
```

check api in [main.py](main.py).
19 changes: 19 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -e

# Ensure that the GITHUB_TOKEN secret is included
if [[ -z "$GITHUB_TOKEN" ]]; then
echo "Set the GITHUB_TOKEN env variable."
exit 1
fi

# Ensure that the file path is present
if [[ -z "$1" ]]; then
echo "You must pass at least one argument to this action, the path to the patching recepie."
exit 1
fi
echo "Appending patch file $1 to main"
cat $1 >> /main.py
echo "Run patch file in main"
python /main.py
18 changes: 18 additions & 0 deletions fixtures/get_file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "file",
"encoding": "base64",
"size": 5362,
"name": "README.md",
"path": "README.md",
"content": "bXkgdXBkYXRlZCBmaWxlIGNvbnRlbnRz",
"sha": "3d21ec53a331a6f037a91c368710b99387d012c1",
"url": "https://api.github.com/repos/octokit/octokit.rb/contents/README.md",
"git_url": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1",
"html_url": "https://github.com/octokit/octokit.rb/blob/master/README.md",
"download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/master/README.md",
"_links": {
"git": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1",
"self": "https://api.github.com/repos/octokit/octokit.rb/contents/README.md",
"html": "https://github.com/octokit/octokit.rb/blob/master/README.md"
}
}
Loading

0 comments on commit d6ec7a7

Please sign in to comment.