Skip to content

Commit

Permalink
Merge pull request #593 from github/blackAction
Browse files Browse the repository at this point in the history
adding black
  • Loading branch information
admiralAwkbar committed Aug 20, 2020
2 parents ed3ae28 + 4f2041d commit ef99a48
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 67 deletions.
103 changes: 69 additions & 34 deletions .automation/test/python/python_good_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@
import requests # pylint: disable=import-error

env = load_dotenv()
api_url = getenv('API_URL', default='https://api.github.com/graphql')
api_url = getenv("API_URL", default="https://api.github.com/graphql")
github_token = getenv("GITHUB_TOKEN", default=None)

if github_token is None:
sys.exit("GitHub Token is not set." +
"Please set the GITHUB_TOKEN env variable in your system or " +
"the .env file of your project.")
sys.exit(
"GitHub Token is not set."
+ "Please set the GITHUB_TOKEN env variable in your system or "
+ "the .env file of your project."
)

client_id = getenv('CLIENT_ID', default='copy_labels.py')
client_id = getenv("CLIENT_ID", default="copy_labels.py")
headers = {
'Authorization': 'bearer {github_token}'.format(github_token=github_token),
'Accept': 'application/vnd.github.bane-preview+json',
'Content-Type': 'application/json'
"Authorization": "bearer {github_token}".format(github_token=github_token),
"Accept": "application/vnd.github.bane-preview+json",
"Content-Type": "application/json",
}


Expand All @@ -40,16 +42,18 @@ def create_label(repo_id, label):
"color": label["color"],
"description": label["description"],
"name": label["name"],
"repositoryId": repo_id
"repositoryId": repo_id,
}
}

with open(path.join(path.dirname(__file__), 'queries/create_label.gql'), 'r') as query_file:
with open(
path.join(path.dirname(__file__), "queries/create_label.gql"), "r"
) as query_file:
query = "".join(query_file.readlines())

payload = {"query": query, "variables": query_variables}
response = requests.post(api_url, data=json.dumps(payload), headers=headers).json()
print('Created label {label}'.format(label=label["name"]))
print("Created label {label}".format(label=label["name"]))

return response

Expand All @@ -64,9 +68,14 @@ def get_labels(owner, repo):
:return: A tuple with the GitHub id for the repository and a list of labels defined in the repository
"""

query_variables = {"owner": owner, "name": repo, }
query_variables = {
"owner": owner,
"name": repo,
}

with open(path.join(path.dirname(__file__), 'queries/get_repo_data.gql'), 'r') as query_file:
with open(
path.join(path.dirname(__file__), "queries/get_repo_data.gql"), "r"
) as query_file:
query = "".join(query_file.readlines())

payload = {"query": query, "variables": query_variables}
Expand All @@ -82,8 +91,10 @@ def get_labels(owner, repo):
return repo_id, labels
else:
raise Exception(
'[ERROR] getting issue labels. Status Code: {status_code} - Message: {result}'.format(
status_code=status_code, result=result["message"]))
"[ERROR] getting issue labels. Status Code: {status_code} - Message: {result}".format(
status_code=status_code, result=result["message"]
)
)


def delete_label(label_id):
Expand All @@ -95,13 +106,12 @@ def delete_label(label_id):
"""

query_variables = {
"deleteLabelInput": {
"clientMutationId": client_id,
"id": label_id,
}
"deleteLabelInput": {"clientMutationId": client_id, "id": label_id}
}

with open(path.join(path.dirname(__file__), 'queries/delete_label.gql'), 'r') as query_file:
with open(
path.join(path.dirname(__file__), "queries/delete_label.gql"), "r"
) as query_file:
query = "".join(query_file.readlines())

payload = {"query": query, "variables": query_variables}
Expand All @@ -111,9 +121,9 @@ def delete_label(label_id):


@click.command()
@click.option('--dry', is_flag=True)
@click.argument('source_repo')
@click.argument('target_repo')
@click.option("--dry", is_flag=True)
@click.argument("source_repo")
@click.argument("target_repo")
def copy_labels(source_repo, target_repo, dry):
"""
Copy labels from the source repository to the target repository.
Expand All @@ -128,30 +138,55 @@ def copy_labels(source_repo, target_repo, dry):
target_owner, target_repo_name = target_repo.split("/")

try:
print('Fetching labels for {source_repo_name} repo.'.format(source_repo_name=source_repo_name))
print(
"Fetching labels for {source_repo_name} repo.".format(
source_repo_name=source_repo_name
)
)
_, source_repo_labels = get_labels(source_owner, source_repo_name)
print('Fetched labels for {source_repo_name}'.format(source_repo_name=source_repo_name))

print('Fetching labels for {target_repo_name} repo.'.format(target_repo_name=target_repo_name))
print(
"Fetched labels for {source_repo_name}".format(
source_repo_name=source_repo_name
)
)

print(
"Fetching labels for {target_repo_name} repo.".format(
target_repo_name=target_repo_name
)
)
target_repo_id, target_repo_labels = get_labels(target_owner, target_repo_name)
print('Fetched labels for {target_repo_name}'.format(target_repo_name=target_repo_name))
print(
"Fetched labels for {target_repo_name}".format(
target_repo_name=target_repo_name
)
)

filtered_labels = list(filter(lambda x: x not in target_repo_labels, source_repo_labels))
filtered_labels = list(
filter(lambda x: x not in target_repo_labels, source_repo_labels)
)

if dry:
print('This is just a dry run. No labels will be copied/created.')
print('{label_count} labels would have been created.'.format(label_count=len(filtered_labels)))
print("This is just a dry run. No labels will be copied/created.")
print(
"{label_count} labels would have been created.".format(
label_count=len(filtered_labels)
)
)
pprint(filtered_labels, indent=4)
else:
print('Preparing to created {label_count} labels in {target_repo}'.format(
label_count=len(filtered_labels), target_repo=target_repo))
print(
"Preparing to created {label_count} labels in {target_repo}".format(
label_count=len(filtered_labels), target_repo=target_repo
)
)

for label in filtered_labels:
create_label(target_repo_id, label)
except Exception as error:
sys.exit(error)

print('Done')
print("Done")


if __name__ == "__main__":
Expand Down
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ FROM wata727/tflint:0.19.0 as tflint
FROM hadolint/hadolint:latest-alpine as dockerfile-lint
FROM assignuser/lintr-lib:latest as lintr-lib
FROM assignuser/chktex-alpine:latest as chktex

##################
# Get base image #
##################
Expand Down Expand Up @@ -73,8 +74,7 @@ RUN apk add --update --no-cache \
py3-setuptools \
R \
readline-dev \
ruby ruby-dev ruby-bundler ruby-rdoc

ruby ruby-dev ruby-bundler ruby-rdoc

########################################
# Copy dependencies files to container #
Expand Down Expand Up @@ -308,8 +308,9 @@ ENV ACTIONS_RUNNER_DEBUG=${ACTIONS_RUNNER_DEBUG} \
VALIDATE_POWERSHELL=${VALIDATE_POWERSHELL} \
VALIDATE_PROTOBUF=${VALIDATE_PROTOBUF} \
VALIDATE_PYTHON=${VALIDATE_PYTHON} \
VALIDATE_PYTHON_PYLINT=${VALIDATE_PYTHON_PYLINT} \
VALIDATE_PYTHON_BLACK=${VALIDATE_PYTHON_BLACK} \
VALIDATE_PYTHON_FLAKE8=${VALIDATE_PYTHON_FLAKE8} \
VALIDATE_PYTHON_PYLINT=${VALIDATE_PYTHON_PYLINT} \
VALIDATE_R=${VALIDATE_R} \
VALIDATE_RAKU=${VALIDATE_RAKU} \
VALIDATE_RUBY=${VALIDATE_RUBY} \
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base
| **PHP** | [PHP built-in linter](https://www.php.net/) / [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) / [PHPStan](https://phpstan.org/n) / [Psalm](https://psalm.dev/) |
| **PowerShell** | [PSScriptAnalyzer](https://github.com/PowerShell/Psscriptanalyzer) |
| **Protocol Buffers** | [protolint](https://github.com/yoheimuta/protolint) |
| **Python3** | [pylint](https://www.pylint.org/) / [flake8](https://flake8.pycqa.org/en/latest/) |
| **Python3** | [pylint](https://www.pylint.org/) / [flake8](https://flake8.pycqa.org/en/latest/) / [black](https://github.com/psf/black) |
| **R** | [lintr](https://github.com/jimhester/lintr) |
| **Raku** | [Raku](https://raku.org) |
| **Ruby** | [RuboCop](https://github.com/rubocop-hq/rubocop) |
Expand Down Expand Up @@ -226,6 +226,7 @@ But if you wish to select or exclude specific linters, we give you full control
| **VALIDATE_PYTHON** | `true` | Flag to enable or disable the linting process of the Python language. (Utilizing: pylint) (keep for backward compatibility) |
| **VALIDATE_PYTHON_PYLINT** | `true` | Flag to enable or disable the linting process of the Python language. (Utilizing: pylint) |
| **VALIDATE_PYTHON_FLAKE8** | `true` | Flag to enable or disable the linting process of the Python language. (Utilizing: flake8) |
| **VALIDATE_PYTHON_BLACK** | `true` | Flag to enable or disable the linting process of the Python language. (Utilizing: black) |
| **VALIDATE_POWERSHELL** | `true` | Flag to enable or disable the linting process of the Powershell language. |
| **VALIDATE_R** | `true` | Flag to enable or disable the linting process of the R language. |
| **VALIDATE_RAKU** | `true` | Flag to enable or disable the linting process of the Raku language. |
Expand Down
12 changes: 8 additions & 4 deletions dependencies/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ verify_ssl = true
[dev-packages]

[packages]
yamllint = "*"
pylint = "*"
yq = "*"
black = "*"
cfn-lint = "*"
terrascan = "*"
flake8 = "*"
pylint = "*"
terrascan = "*"
yamllint = "*"
yq = "*"

[requires]
python_version = "3.8"

[pipenv]
allow_prereleases = true
Loading

0 comments on commit ef99a48

Please sign in to comment.