Skip to content

Commit

Permalink
flesh out entrypoint, give a more descriptive name
Browse files Browse the repository at this point in the history
  • Loading branch information
Raymond Gasper committed May 26, 2020
1 parent 555f6a9 commit 1718686
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 40 deletions.
129 changes: 97 additions & 32 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@

# Created by https://www.gitignore.io/api/python,visualstudiocode,vim,sublimetext,git
# Edit at https://www.gitignore.io/?templates=python,visualstudiocode,vim,sublimetext,git

### Git ###
# Created by git for backups. To disable backups in Git:
# $ git config --global mergetool.keepBackup false
*.orig

# Created by git when using merge tools for conflicts
*.BACKUP.*
*.BASE.*
*.LOCAL.*
*.REMOTE.*
*_BACKUP_*.txt
*_BASE_*.txt
*_LOCAL_*.txt
*_REMOTE_*.txt

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -47,24 +67,13 @@ htmlcov/
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

Expand All @@ -74,13 +83,6 @@ docs/_build/
# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

Expand All @@ -91,32 +93,24 @@ ipython_config.py
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
# celery beat schedule file
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# mkdocs documentation
/site

Expand All @@ -127,3 +121,74 @@ dmypy.json

# Pyre type checker
.pyre/

### SublimeText ###
# Cache files for Sublime Text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache

# Workspace files are user-specific
*.sublime-workspace

# Project files should be checked into the repository, unless a significant
# proportion of contributors will probably not be using Sublime Text
# *.sublime-project

# SFTP configuration file
sftp-config.json

# Package control specific files
Package Control.last-run
Package Control.ca-list
Package Control.ca-bundle
Package Control.system-ca-bundle
Package Control.cache/
Package Control.ca-certs/
Package Control.merged-ca-bundle
Package Control.user-ca-bundle
oscrypto-ca-bundle.crt
bh_unicode_properties.cache

# Sublime-github package stores a github token in this file
# https://packagecontrol.io/packages/sublime-github
GitHub.sublime-settings

### Vim ###
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]

# Session
Session.vim
Sessionx.vim

# Temporary
.netrwhist
*~

# Auto-generated tag files
tags

# Persistent undo
[._]*.un~

# Coc configuration directory
.vim

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

### VisualStudioCode Patch ###
# Ignore all local history of files
.history

# End of https://www.gitignore.io/api/python,visualstudiocode,vim,sublimetext,git

7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
FROM python:3
FROM python:3-slim

RUN apt update && apt -y upgrade
RUN pip install black

COPY entrypoint.sh /entrypoint.sh
COPY run_black_on_git_diff_adds.sh /run_black_on_git_diff_adds.sh

ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/run_black_on_git_diff_adds.sh"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Readme

This is a github action that will run the [black python formatter](https://github.com/psf/black) on a PR, but only on the files changed in your PR. This helps avoid situations where one runs the formatter on an old code base and gets hundreds of files with warnings and hints.
This is a github action that will run the [black python formatter](https://github.com/psf/black) on a PR, but only on the files changed in your PR. This helps avoid situations where one runs the formatter on an old code base and gets hundreds of files with warnings and hints. Entrypoint code is inspired by the excellent [typilus](https://github.com/typilus/typilus-action/blob/master/entrypoint.py)

## Installation

Expand Down
4 changes: 0 additions & 4 deletions entrypoint.sh

This file was deleted.

12 changes: 12 additions & 0 deletions run_black_on_git_diff_adds.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
if [[ ${GITHUB_EVENT_NAME} != "pull_request" ]]
then
echo "this action runs only on pull request events"
exit 1
fi

github_pr_url=`echo -En ${GITHUB_EVENT_PATH} | jq '.pull_request.url'`
github_diff=`curl --request GET --url ${github_pr_url} --header "authorization: Bearer ${GITHUB_TOKEN}" --header "Accept: application/vnd.github.v3.diff"`
list_of_edited_files=`echo -En ${github_diff} | grep -E -- "\+\+\+ " | awk '{print $2}' | grep -Po -- "(?<=[ab]/).+(.py$)"`

black ${list_of_edited_files}

0 comments on commit 1718686

Please sign in to comment.