From 438cff319b352712b6e75e6ae6c84beb4ad19907 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 12 Jun 2022 03:15:08 +0000 Subject: [PATCH 01/28] =?UTF-8?q?Bump=20version:=201.0.0=20=E2=86=92=201.0?= =?UTF-8?q?.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 860be11..741cf0e 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.0.0 +current_version = 1.0.1 commit = True tag = False diff --git a/setup.py b/setup.py index d5a2463..2df1eab 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ setup( name="github-deploy", - version="1.0.0", + version="1.0.1", description="Deploy yaml files to a large number of repositories in seconds.", long_description=LONG_DESCRIPTION, long_description_content_type=LONG_DESCRIPTION_TYPE, From cad47bc792e87066b72eba8ec7cce786982b31c0 Mon Sep 17 00:00:00 2001 From: jackton1 Date: Sun, 12 Jun 2022 03:15:21 +0000 Subject: [PATCH 02/28] =?UTF-8?q?Upgraded=20from=20v1.0.0=20=E2=86=92=20v1?= =?UTF-8?q?.0.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b51c49..27a9493 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [v1.0.1](https://github.com/tj-python/github-deploy/tree/v1.0.1) (2022-06-12) + +[Full Changelog](https://github.com/tj-python/github-deploy/compare/v1.0.0...v1.0.1) + +**Merged pull requests:** + +- Bump actions/setup-python from 2 to 4 [\#14](https://github.com/tj-python/github-deploy/pull/14) ([dependabot[bot]](https://github.com/apps/dependabot)) +- Bump peter-evans/create-pull-request from 3 to 4 [\#13](https://github.com/tj-python/github-deploy/pull/13) ([dependabot[bot]](https://github.com/apps/dependabot)) +- Bump tj-actions/semver-diff from 1.2.0 to 2.0.0 [\#12](https://github.com/tj-python/github-deploy/pull/12) ([dependabot[bot]](https://github.com/apps/dependabot)) +- Bump tj-actions/github-changelog-generator from 1.8 to 1.13 [\#11](https://github.com/tj-python/github-deploy/pull/11) ([dependabot[bot]](https://github.com/apps/dependabot)) +- Bump actions/checkout from 2 to 3 [\#10](https://github.com/tj-python/github-deploy/pull/10) ([dependabot[bot]](https://github.com/apps/dependabot)) +- feat: Improve error handling [\#9](https://github.com/tj-python/github-deploy/pull/9) ([jackton1](https://github.com/jackton1)) +- Upgraded 0.0.9 → v1.0.0 [\#8](https://github.com/tj-python/github-deploy/pull/8) ([jackton1](https://github.com/jackton1)) + ## [v1.0.0](https://github.com/tj-python/github-deploy/tree/v1.0.0) (2022-02-12) [Full Changelog](https://github.com/tj-python/github-deploy/compare/0.0.9...v1.0.0) @@ -22,15 +36,15 @@ ## [0.0.7](https://github.com/tj-python/github-deploy/tree/0.0.7) (2021-11-15) -[Full Changelog](https://github.com/tj-python/github-deploy/compare/0.0.5...0.0.7) +[Full Changelog](https://github.com/tj-python/github-deploy/compare/0.0.6...0.0.7) -## [0.0.5](https://github.com/tj-python/github-deploy/tree/0.0.5) (2021-11-15) +## [0.0.6](https://github.com/tj-python/github-deploy/tree/0.0.6) (2021-11-15) -[Full Changelog](https://github.com/tj-python/github-deploy/compare/0.0.6...0.0.5) +[Full Changelog](https://github.com/tj-python/github-deploy/compare/0.0.5...0.0.6) -## [0.0.6](https://github.com/tj-python/github-deploy/tree/0.0.6) (2021-11-15) +## [0.0.5](https://github.com/tj-python/github-deploy/tree/0.0.5) (2021-11-15) -[Full Changelog](https://github.com/tj-python/github-deploy/compare/0.0.4...0.0.6) +[Full Changelog](https://github.com/tj-python/github-deploy/compare/0.0.4...0.0.5) **Merged pull requests:** From 6fc419417ef5853c6cf858189182117a6aad8310 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sat, 11 Jun 2022 23:20:03 -0400 Subject: [PATCH 03/28] Update main.py --- github_deploy/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github_deploy/main.py b/github_deploy/main.py index 2acef84..8322d65 100644 --- a/github_deploy/main.py +++ b/github_deploy/main.py @@ -24,7 +24,7 @@ def get_command(self, ctx, name): eval(code, ns, ns) return ns['main'] - ctx.fail("Invalid Command: {name}".format(name=name)) + ctx.fail("Invalid Command \"{name}\"".format(name=name)) main = GithubDeploy( From 42a857e0413d95389b566d188d99ce531c11e7dd Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sat, 11 Jun 2022 23:20:59 -0400 Subject: [PATCH 04/28] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index b099986..2f9fd94 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,6 @@ This can introduce a number challenges one of which is maintaining consistency a > For example adding a github action or maintaing a consistent pull request template accross your organization. - ## Solution `github-deploy` makes maintaining such configurations as easy as a single command. From 24b554d3698c114e7ecb00612a45426257839979 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sat, 11 Jun 2022 23:23:58 -0400 Subject: [PATCH 05/28] Create codacy.yml --- .github/workflows/codacy.yml | 60 ++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 .github/workflows/codacy.yml diff --git a/.github/workflows/codacy.yml b/.github/workflows/codacy.yml new file mode 100644 index 0000000..8be0fdb --- /dev/null +++ b/.github/workflows/codacy.yml @@ -0,0 +1,60 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +# This workflow checks out code, performs a Codacy security scan +# and integrates the results with the +# GitHub Advanced Security code scanning feature. For more information on +# the Codacy security scan action usage and parameters, see +# https://github.com/codacy/codacy-analysis-cli-action. +# For more information on Codacy Analysis CLI in general, see +# https://github.com/codacy/codacy-analysis-cli. + +name: Codacy Security Scan + +on: + push: + branches: [ "main" ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "main" ] + schedule: + - cron: '39 21 * * 4' + +permissions: + contents: read + +jobs: + codacy-security-scan: + permissions: + contents: read # for actions/checkout to fetch code + security-events: write # for github/codeql-action/upload-sarif to upload SARIF results + name: Codacy Security Scan + runs-on: ubuntu-latest + steps: + # Checkout the repository to the GitHub Actions runner + - name: Checkout code + uses: actions/checkout@v3 + + # Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis + - name: Run Codacy Analysis CLI + uses: codacy/codacy-analysis-cli-action@d840f886c4bd4edc059706d09c6a1586111c540b + with: + # Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository + # You can also omit the token and run the tools that support default configurations + project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} + verbose: true + output: results.sarif + format: sarif + # Adjust severity of non-security issues + gh-code-scanning-compat: true + # Force 0 exit code to allow SARIF file generation + # This will handover control about PR rejection to the GitHub side + max-allowed-issues: 2147483647 + + # Upload the SARIF file generated in the previous step + - name: Upload SARIF results file + uses: github/codeql-action/upload-sarif@v2 + with: + sarif_file: results.sarif From 2b27932ef2e035d58714764c34334e64bfb33ac0 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sat, 11 Jun 2022 23:33:14 -0400 Subject: [PATCH 06/28] Fixed lint errors. --- github_deploy/__init__.py | 2 +- github_deploy/commands/__init__.py | 2 +- github_deploy/commands/_utils.py | 2 +- github_deploy/commands/delete.py | 16 +++++++++------- github_deploy/commands/upload.py | 19 +++++++++++-------- github_deploy/main.py | 19 +++++++++++-------- setup.py | 2 +- 7 files changed, 35 insertions(+), 27 deletions(-) diff --git a/github_deploy/__init__.py b/github_deploy/__init__.py index 0260537..8db66d3 100644 --- a/github_deploy/__init__.py +++ b/github_deploy/__init__.py @@ -1 +1 @@ -__path__ = __import__('pkgutil').extend_path(__path__, __name__) \ No newline at end of file +__path__ = __import__("pkgutil").extend_path(__path__, __name__) diff --git a/github_deploy/commands/__init__.py b/github_deploy/commands/__init__.py index 0260537..8db66d3 100644 --- a/github_deploy/commands/__init__.py +++ b/github_deploy/commands/__init__.py @@ -1 +1 @@ -__path__ = __import__('pkgutil').extend_path(__path__, __name__) \ No newline at end of file +__path__ = __import__("pkgutil").extend_path(__path__, __name__) diff --git a/github_deploy/commands/_utils.py b/github_deploy/commands/_utils.py index 67cdb6b..ad0bb0d 100644 --- a/github_deploy/commands/_utils.py +++ b/github_deploy/commands/_utils.py @@ -3,4 +3,4 @@ def get_repo(*, org, project): def can_upload(*, repo, include_private): - return True if include_private and repo['private'] == True else not repo['private'] + return True if include_private and repo["private"] == True else not repo["private"] diff --git a/github_deploy/commands/delete.py b/github_deploy/commands/delete.py index f85c9c0..499cda0 100644 --- a/github_deploy/commands/delete.py +++ b/github_deploy/commands/delete.py @@ -80,9 +80,7 @@ async def check_exists(*, session, repo, dest, token, semaphore, skip_missing): return response -async def handle_file_delete( - *, repo, dest, token, semaphore, session -): +async def handle_file_delete(*, repo, dest, token, semaphore, session): check_exists_response = await check_exists( session=session, repo=repo, @@ -114,7 +112,7 @@ async def handle_file_delete( exists=exists, current_sha=current_sha, ) - + if delete_response: return click.style( "Successfully deleted contents at {repo}/{dest}".format( @@ -124,7 +122,7 @@ async def handle_file_delete( fg="green", bold=True, ) - + return click.style( "No content found at {repo}/{dest}".format(repo=repo, dest=dest), fg="blue", @@ -154,7 +152,7 @@ async def list_repos(*, session, org, token): prompt=click.style("Enter your personal access token", bold=True), help="Personal Access token with read and write access to org.", hide_input=True, - envvar='TOKEN', + envvar="TOKEN", ) @click.option( "--dest", @@ -182,7 +180,11 @@ async def main(org, token, dest): fg="green", ) ) - click.echo(click.style('Deleting "{path}" for all repositories:'.format(path=dest), fg="blue")) + click.echo( + click.style( + 'Deleting "{path}" for all repositories:'.format(path=dest), fg="blue" + ) + ) click.echo("\n".join(repos)) c = click.prompt(click.style("Continue? [YN] ", fg="blue")) diff --git a/github_deploy/commands/upload.py b/github_deploy/commands/upload.py index 47d453c..4c24d77 100644 --- a/github_deploy/commands/upload.py +++ b/github_deploy/commands/upload.py @@ -120,7 +120,7 @@ async def handle_file_upload( path=dest, ), fg="blue", - bold=True + bold=True, ) else: @@ -154,7 +154,7 @@ async def handle_file_upload( dest=upload_response["content"]["path"], ), fg="green", - bold=True + bold=True, ) @@ -180,7 +180,7 @@ async def list_repos(*, session, org, token): prompt=click.style("Enter your personal access token", bold=True), help="Personal Access token with read and write access to org.", hide_input=True, - envvar='TOKEN', + envvar="TOKEN", ) @click.option( "--source", @@ -219,10 +219,12 @@ async def main(org, token, source, dest, overwrite, private): for r in response["items"] if not r["archived"] and can_upload(repo=r, include_private=private) ] - repo_type = 'public and private' if private else 'public' + repo_type = "public and private" if private else "public" click.echo( click.style( - "Found '{}' repositories non archived {} repositories:".format(len(repos), repo_type), + "Found '{}' repositories non archived {} repositories:".format( + len(repos), repo_type + ), fg="green", ) ) @@ -238,11 +240,12 @@ async def main(org, token, source, dest, overwrite, private): ) ) deploy_msg = ( - 'Deploying "{source}" to "{path}" for all repositories'.format(source=source, path=dest) + 'Deploying "{source}" to "{path}" for all repositories'.format( + source=source, path=dest + ) if overwrite else 'Deploying "{source}" to repositories that don\'t already have contents at "{path}"'.format( - source=source, - path=dest + source=source, path=dest ) ) click.echo(click.style(deploy_msg, fg="blue")) diff --git a/github_deploy/main.py b/github_deploy/main.py index 2acef84..351fc7f 100644 --- a/github_deploy/main.py +++ b/github_deploy/main.py @@ -1,35 +1,38 @@ import asyncclick as click import os -plugin_folder = os.path.join(os.path.dirname(__file__), 'commands') +plugin_folder = os.path.join(os.path.dirname(__file__), "commands") class GithubDeploy(click.MultiCommand): - def list_commands(self, ctx): rv = [] for filename in os.listdir(plugin_folder): - if filename.endswith('.py') and not filename.startswith('__init__') and not filename.startswith('_'): + if ( + filename.endswith(".py") + and not filename.startswith("__init__") + and not filename.startswith("_") + ): rv.append(filename[:-3]) rv.sort() return rv def get_command(self, ctx, name): ns = {} - fn = os.path.join(plugin_folder, name + '.py') + fn = os.path.join(plugin_folder, name + ".py") if os.path.exists(fn): with open(fn) as f: - code = compile(f.read(), fn, 'exec') + code = compile(f.read(), fn, "exec") eval(code, ns, ns) - return ns['main'] + return ns["main"] ctx.fail("Invalid Command: {name}".format(name=name)) main = GithubDeploy( - help='Deploy changes to multiple github repositories using a single command.', + help="Deploy changes to multiple github repositories using a single command.", ) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/setup.py b/setup.py index d5a2463..841b4fa 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,7 @@ author_email="jtonye@ymail.com", license="MIT", packages=find_packages(), - python_requires='>=3.6', + python_requires=">=3.6", extras_require=extras_require, install_requires=[ "asyncclick", From 44414324c163bb793700e59af00698b5cb5f97fd Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sat, 11 Jun 2022 23:34:57 -0400 Subject: [PATCH 07/28] Fixed lint errors. --- github_deploy/commands/_utils.py | 6 +++++- github_deploy/commands/delete.py | 16 ++++++++++++---- github_deploy/commands/upload.py | 20 +++++++++++++++----- setup.py | 8 +++++++- 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/github_deploy/commands/_utils.py b/github_deploy/commands/_utils.py index ad0bb0d..cc4ea9c 100644 --- a/github_deploy/commands/_utils.py +++ b/github_deploy/commands/_utils.py @@ -3,4 +3,8 @@ def get_repo(*, org, project): def can_upload(*, repo, include_private): - return True if include_private and repo["private"] == True else not repo["private"] + return ( + True + if include_private and repo["private"] == True + else not repo["private"] + ) diff --git a/github_deploy/commands/delete.py b/github_deploy/commands/delete.py index 499cda0..e045109 100644 --- a/github_deploy/commands/delete.py +++ b/github_deploy/commands/delete.py @@ -63,7 +63,9 @@ async def delete_content( url = BASE_URL.format(repo=repo, path=dest) async with semaphore: - response = await delete(session=session, url=url, data=data, headers=headers) + response = await delete( + session=session, url=url, data=data, headers=headers + ) return response @@ -74,7 +76,10 @@ async def check_exists(*, session, repo, dest, token, semaphore, skip_missing): async with semaphore: response = await get( - session=session, url=url, headers=headers, skip_missing=skip_missing + session=session, + url=url, + headers=headers, + skip_missing=skip_missing, ) return response @@ -176,13 +181,16 @@ async def main(org, token, dest): ] click.echo( click.style( - "Found '{}' repositories non archived repositories".format(len(repos)), + "Found '{}' repositories non archived repositories".format( + len(repos) + ), fg="green", ) ) click.echo( click.style( - 'Deleting "{path}" for all repositories:'.format(path=dest), fg="blue" + 'Deleting "{path}" for all repositories:'.format(path=dest), + fg="blue", ) ) click.echo("\n".join(repos)) diff --git a/github_deploy/commands/upload.py b/github_deploy/commands/upload.py index 4c24d77..68d6336 100644 --- a/github_deploy/commands/upload.py +++ b/github_deploy/commands/upload.py @@ -70,7 +70,9 @@ async def upload_content( return data = { - "message": "Updated {}".format(dest) if exists else "Added {}".format(dest), + "message": "Updated {}".format(dest) + if exists + else "Added {}".format(dest), "content": base64_content, } if exists: @@ -79,7 +81,9 @@ async def upload_content( url = BASE_URL.format(repo=repo, path=dest) async with semaphore: - response = await put(session=session, url=url, data=data, headers=headers) + response = await put( + session=session, url=url, data=data, headers=headers + ) return response @@ -90,7 +94,10 @@ async def check_exists(*, session, repo, dest, token, semaphore, skip_missing): async with semaphore: response = await get( - session=session, url=url, headers=headers, skip_missing=skip_missing + session=session, + url=url, + headers=headers, + skip_missing=skip_missing, ) return response @@ -195,7 +202,9 @@ async def list_repos(*, session, org, token): ) @click.option( "--overwrite/--no-overwrite", - prompt=click.style("Should we overwrite existing contents at this path", fg="blue"), + prompt=click.style( + "Should we overwrite existing contents at this path", fg="blue" + ), help="Overwrite existing files.", default=False, ) @@ -217,7 +226,8 @@ async def main(org, token, source, dest, overwrite, private): repos = [ get_repo(org=org, project=r["name"]) for r in response["items"] - if not r["archived"] and can_upload(repo=r, include_private=private) + if not r["archived"] + and can_upload(repo=r, include_private=private) ] repo_type = "public and private" if private else "public" click.echo( diff --git a/setup.py b/setup.py index 841b4fa..5c1a858 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,13 @@ "gh-deploy=github_deploy.main:main", ], }, - keywords=["yaml", "deploy", "poly repository", "github", "single configuration"], + keywords=[ + "yaml", + "deploy", + "poly repository", + "github", + "single configuration", + ], author="Tonye Jack", author_email="jtonye@ymail.com", license="MIT", From 554dcf877d74a0b64111a296aa726c7d7dd154e5 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sat, 11 Jun 2022 23:46:49 -0400 Subject: [PATCH 08/28] Refactor application --- github_deploy/commands/_http_utils.py | 64 +++++++++++++++++++++++++++ github_deploy/commands/_utils.py | 2 +- github_deploy/commands/delete.py | 48 +------------------- github_deploy/commands/upload.py | 48 +------------------- 4 files changed, 69 insertions(+), 93 deletions(-) create mode 100644 github_deploy/commands/_http_utils.py diff --git a/github_deploy/commands/_http_utils.py b/github_deploy/commands/_http_utils.py new file mode 100644 index 0000000..d736fe7 --- /dev/null +++ b/github_deploy/commands/_http_utils.py @@ -0,0 +1,64 @@ +import ssl +import certifi + +import asyncclick as click + +from github_deploy.commands._constants import REPOS_URL + + +async def get(*, session, url, headers=None, skip_missing=False): + ssl_context = ssl.create_default_context(cafile=certifi.where()) + + async with session.get( + url, + headers=headers, + timeout=70, + ssl_context=ssl_context, + raise_for_status=not skip_missing, + ) as response: + if skip_missing and response.status == 404: + return {} + + value = await response.json() + return value + + +async def put(*, session, url, data, headers=None): + ssl_context = ssl.create_default_context(cafile=certifi.where()) + + async with session.put( + url, + json=data, + headers=headers, + timeout=70, + ssl_context=ssl_context, + raise_for_status=True, + ) as response: + value = await response.json() + return value + + +async def delete(*, session, url, data, headers=None): + ssl_context = ssl.create_default_context(cafile=certifi.where()) + + async with session.delete( + url, + json=data, + headers=headers, + timeout=70, + ssl_context=ssl_context, + raise_for_status=True, + ) as response: + value = await response.json() + return value + + +async def list_repos(*, session, org, token): + headers = { + "Authorization": "token {token}".format(token=token), + "Accept": "application/vnd.github.v3+json", + } + url = REPOS_URL.format(org=org) + click.echo("Retrieving repos at {}".format(url)) + response = await get(session=session, url=url, headers=headers) + return response diff --git a/github_deploy/commands/_utils.py b/github_deploy/commands/_utils.py index cc4ea9c..109bd3f 100644 --- a/github_deploy/commands/_utils.py +++ b/github_deploy/commands/_utils.py @@ -5,6 +5,6 @@ def get_repo(*, org, project): def can_upload(*, repo, include_private): return ( True - if include_private and repo["private"] == True + if include_private and repo["private"] is True else not repo["private"] ) diff --git a/github_deploy/commands/delete.py b/github_deploy/commands/delete.py index e045109..8ead88e 100644 --- a/github_deploy/commands/delete.py +++ b/github_deploy/commands/delete.py @@ -1,46 +1,13 @@ import asyncio -import ssl import aiohttp import asyncclick as click -import certifi -from github_deploy.commands._constants import BASE_URL, REPOS_URL +from github_deploy.commands._constants import BASE_URL +from github_deploy.commands._http_utils import delete, get, list_repos from github_deploy.commands._utils import get_repo -async def get(*, session, url, headers=None, skip_missing=False): - ssl_context = ssl.create_default_context(cafile=certifi.where()) - - async with session.get( - url, - headers=headers, - timeout=70, - ssl_context=ssl_context, - raise_for_status=not skip_missing, - ) as response: - if skip_missing and response.status == 404: - return {} - - value = await response.json() - return value - - -async def delete(*, session, url, data, headers=None): - ssl_context = ssl.create_default_context(cafile=certifi.where()) - - async with session.delete( - url, - json=data, - headers=headers, - timeout=70, - ssl_context=ssl_context, - raise_for_status=True, - ) as response: - value = await response.json() - return value - - async def delete_content( *, session, @@ -135,17 +102,6 @@ async def handle_file_delete(*, repo, dest, token, semaphore, session): ) -async def list_repos(*, session, org, token): - headers = { - "Authorization": "token {token}".format(token=token), - "Accept": "application/vnd.github.v3+json", - } - url = REPOS_URL.format(org=org) - click.echo("Retrieving repos at {}".format(url)) - response = await get(session=session, url=url, headers=headers) - return response - - @click.command() @click.option( "--org", diff --git a/github_deploy/commands/upload.py b/github_deploy/commands/upload.py index 68d6336..fe58e6d 100644 --- a/github_deploy/commands/upload.py +++ b/github_deploy/commands/upload.py @@ -1,48 +1,15 @@ import asyncio import base64 -import ssl import aiofiles import aiohttp import asyncclick as click -import certifi -from github_deploy.commands._constants import BASE_URL, REPOS_URL +from github_deploy.commands._constants import BASE_URL +from github_deploy.commands._http_utils import put, list_repos, get from github_deploy.commands._utils import get_repo, can_upload -async def get(*, session, url, headers=None, skip_missing=False): - ssl_context = ssl.create_default_context(cafile=certifi.where()) - - async with session.get( - url, - headers=headers, - timeout=70, - ssl_context=ssl_context, - raise_for_status=not skip_missing, - ) as response: - if skip_missing and response.status == 404: - return {} - - value = await response.json() - return value - - -async def put(*, session, url, data, headers=None): - ssl_context = ssl.create_default_context(cafile=certifi.where()) - - async with session.put( - url, - json=data, - headers=headers, - timeout=70, - ssl_context=ssl_context, - raise_for_status=True, - ) as response: - value = await response.json() - return value - - async def upload_content( *, session, @@ -165,17 +132,6 @@ async def handle_file_upload( ) -async def list_repos(*, session, org, token): - headers = { - "Authorization": "token {token}".format(token=token), - "Accept": "application/vnd.github.v3+json", - } - url = REPOS_URL.format(org=org) - click.echo("Retrieving repos at {}".format(url)) - response = await get(session=session, url=url, headers=headers) - return response - - @click.command() @click.option( "--org", From 989b6bdc749342f2e2bbe8daf195b5f5340bff2e Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sat, 11 Jun 2022 23:48:15 -0400 Subject: [PATCH 09/28] Fixed lint errors. --- github_deploy/main.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/github_deploy/main.py b/github_deploy/main.py index 7508a4e..d93075b 100644 --- a/github_deploy/main.py +++ b/github_deploy/main.py @@ -9,9 +9,9 @@ def list_commands(self, ctx): rv = [] for filename in os.listdir(plugin_folder): if ( - filename.endswith(".py") - and not filename.startswith("__init__") - and not filename.startswith("_") + filename.endswith(".py") + and not filename.startswith("__init__") + and not filename.startswith("_") ): rv.append(filename[:-3]) rv.sort() @@ -31,7 +31,9 @@ def get_command(self, ctx, name): main = GithubDeploy( - help="Deploy changes to multiple github repositories using a single command.", + help=( + "Deploy changes to multiple github repositories using a single command." + ), ) if __name__ == "__main__": From 4eeb7f0ead2e372ba57a66b5d602c8822eb4fa87 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sat, 11 Jun 2022 23:49:48 -0400 Subject: [PATCH 10/28] Fixed lint errors. --- github_deploy/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/github_deploy/main.py b/github_deploy/main.py index d93075b..c7cce59 100644 --- a/github_deploy/main.py +++ b/github_deploy/main.py @@ -32,7 +32,8 @@ def get_command(self, ctx, name): main = GithubDeploy( help=( - "Deploy changes to multiple github repositories using a single command." + "Deploy changes to multiple github repositories using " + "a single command." ), ) From 4e671c1d4f873e545f361aac75d7e9011973c32d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 13 Jun 2022 14:23:14 +0000 Subject: [PATCH 11/28] Bump codacy/codacy-analysis-cli-action from 1.1.0 to 4.0.2 Bumps [codacy/codacy-analysis-cli-action](https://github.com/codacy/codacy-analysis-cli-action) from 1.1.0 to 4.0.2. - [Release notes](https://github.com/codacy/codacy-analysis-cli-action/releases) - [Commits](https://github.com/codacy/codacy-analysis-cli-action/compare/d840f886c4bd4edc059706d09c6a1586111c540b...f38648320929161d81646834fbee4d75f6502aea) --- updated-dependencies: - dependency-name: codacy/codacy-analysis-cli-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/codacy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codacy.yml b/.github/workflows/codacy.yml index 8be0fdb..f810d5b 100644 --- a/.github/workflows/codacy.yml +++ b/.github/workflows/codacy.yml @@ -39,7 +39,7 @@ jobs: # Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis - name: Run Codacy Analysis CLI - uses: codacy/codacy-analysis-cli-action@d840f886c4bd4edc059706d09c6a1586111c540b + uses: codacy/codacy-analysis-cli-action@f38648320929161d81646834fbee4d75f6502aea with: # Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository # You can also omit the token and run the tools that support default configurations From b9715b362f6988b787c85a0dda4e7c7a3865ed4c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Jul 2022 13:54:49 +0000 Subject: [PATCH 12/28] Bump tj-actions/github-changelog-generator from 1.13 to 1.14 Bumps [tj-actions/github-changelog-generator](https://github.com/tj-actions/github-changelog-generator) from 1.13 to 1.14. - [Release notes](https://github.com/tj-actions/github-changelog-generator/releases) - [Changelog](https://github.com/tj-actions/github-changelog-generator/blob/main/HISTORY.md) - [Commits](https://github.com/tj-actions/github-changelog-generator/compare/v1.13...v1.14) --- updated-dependencies: - dependency-name: tj-actions/github-changelog-generator dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 07d47a7..128dd03 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -43,7 +43,7 @@ jobs: TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - name: Generate CHANGELOG - uses: tj-actions/github-changelog-generator@v1.13 + uses: tj-actions/github-changelog-generator@v1.14 - name: Create Pull Request uses: peter-evans/create-pull-request@v4 From 8cea3ff63f1597a36f78054918f37220a9528384 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 19 Aug 2022 13:34:20 +0000 Subject: [PATCH 13/28] Bump codacy/codacy-analysis-cli-action from 4.0.2 to 4.1 Bumps [codacy/codacy-analysis-cli-action](https://github.com/codacy/codacy-analysis-cli-action) from 4.0.2 to 4.1. - [Release notes](https://github.com/codacy/codacy-analysis-cli-action/releases) - [Commits](https://github.com/codacy/codacy-analysis-cli-action/compare/f38648320929161d81646834fbee4d75f6502aea...8abcaf1b06f1d9bd44d5795bbc679440aeb6ea7c) --- updated-dependencies: - dependency-name: codacy/codacy-analysis-cli-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/codacy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codacy.yml b/.github/workflows/codacy.yml index f810d5b..7a1f3c7 100644 --- a/.github/workflows/codacy.yml +++ b/.github/workflows/codacy.yml @@ -39,7 +39,7 @@ jobs: # Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis - name: Run Codacy Analysis CLI - uses: codacy/codacy-analysis-cli-action@f38648320929161d81646834fbee4d75f6502aea + uses: codacy/codacy-analysis-cli-action@8abcaf1b06f1d9bd44d5795bbc679440aeb6ea7c with: # Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository # You can also omit the token and run the tools that support default configurations From 95173a798da6914f37087f226ce90bacdaeb18db Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Sep 2022 14:04:34 +0000 Subject: [PATCH 14/28] Bump tj-actions/github-changelog-generator from 1.14 to 1.15 Bumps [tj-actions/github-changelog-generator](https://github.com/tj-actions/github-changelog-generator) from 1.14 to 1.15. - [Release notes](https://github.com/tj-actions/github-changelog-generator/releases) - [Changelog](https://github.com/tj-actions/github-changelog-generator/blob/main/HISTORY.md) - [Commits](https://github.com/tj-actions/github-changelog-generator/compare/v1.14...v1.15) --- updated-dependencies: - dependency-name: tj-actions/github-changelog-generator dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 128dd03..07043bd 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -43,7 +43,7 @@ jobs: TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - name: Generate CHANGELOG - uses: tj-actions/github-changelog-generator@v1.14 + uses: tj-actions/github-changelog-generator@v1.15 - name: Create Pull Request uses: peter-evans/create-pull-request@v4 From c798e54eab872457dbd3f2b237b97eb72d979a9e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 20 Sep 2022 14:06:50 +0000 Subject: [PATCH 15/28] Bump tj-actions/semver-diff from 2.0.0 to 2.1.0 Bumps [tj-actions/semver-diff](https://github.com/tj-actions/semver-diff) from 2.0.0 to 2.1.0. - [Release notes](https://github.com/tj-actions/semver-diff/releases) - [Changelog](https://github.com/tj-actions/semver-diff/blob/main/HISTORY.md) - [Commits](https://github.com/tj-actions/semver-diff/compare/v2.0.0...v2.1.0) --- updated-dependencies: - dependency-name: tj-actions/semver-diff dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 07043bd..43ab2a6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -14,7 +14,7 @@ jobs: - name: Run semver-diff id: semver-diff - uses: tj-actions/semver-diff@v2.0.0 + uses: tj-actions/semver-diff@v2.1.0 - name: Set up Python uses: actions/setup-python@v4 From ee15f717637f88f982373b90dd6824fb0788b1c9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 21 Sep 2022 14:16:40 +0000 Subject: [PATCH 16/28] Bump codacy/codacy-analysis-cli-action from 4.1.0 to 4.2.0 Bumps [codacy/codacy-analysis-cli-action](https://github.com/codacy/codacy-analysis-cli-action) from 4.1.0 to 4.2.0. - [Release notes](https://github.com/codacy/codacy-analysis-cli-action/releases) - [Commits](https://github.com/codacy/codacy-analysis-cli-action/compare/8abcaf1b06f1d9bd44d5795bbc679440aeb6ea7c...d43127fe38d20c527dc1951ae5aea23148bab738) --- updated-dependencies: - dependency-name: codacy/codacy-analysis-cli-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/codacy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codacy.yml b/.github/workflows/codacy.yml index 7a1f3c7..ae02244 100644 --- a/.github/workflows/codacy.yml +++ b/.github/workflows/codacy.yml @@ -39,7 +39,7 @@ jobs: # Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis - name: Run Codacy Analysis CLI - uses: codacy/codacy-analysis-cli-action@8abcaf1b06f1d9bd44d5795bbc679440aeb6ea7c + uses: codacy/codacy-analysis-cli-action@d43127fe38d20c527dc1951ae5aea23148bab738 with: # Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository # You can also omit the token and run the tools that support default configurations From 8d073c6c41d0349cebfef45fd5b6ba42a2707865 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 18 Oct 2022 13:36:14 +0000 Subject: [PATCH 17/28] Bump pascalgn/automerge-action from 0.15.3 to 0.15.5 Bumps [pascalgn/automerge-action](https://github.com/pascalgn/automerge-action) from 0.15.3 to 0.15.5. - [Release notes](https://github.com/pascalgn/automerge-action/releases) - [Commits](https://github.com/pascalgn/automerge-action/compare/v0.15.3...v0.15.5) --- updated-dependencies: - dependency-name: pascalgn/automerge-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/auto-merge.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml index 59f687f..cb1f956 100644 --- a/.github/workflows/auto-merge.yml +++ b/.github/workflows/auto-merge.yml @@ -16,7 +16,7 @@ jobs: github.actor == 'renovate' steps: - name: automerge - uses: pascalgn/automerge-action@v0.15.3 + uses: pascalgn/automerge-action@v0.15.5 env: GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} MERGE_METHOD: "rebase" From 1e5dd2923c720e0ac13a68af00c5e379bb16be7a Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Wed, 26 Oct 2022 15:47:06 -0600 Subject: [PATCH 18/28] fix: bug with listing repositories --- github_deploy/commands/_http_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github_deploy/commands/_http_utils.py b/github_deploy/commands/_http_utils.py index d736fe7..2cb9ae2 100644 --- a/github_deploy/commands/_http_utils.py +++ b/github_deploy/commands/_http_utils.py @@ -55,8 +55,8 @@ async def delete(*, session, url, data, headers=None): async def list_repos(*, session, org, token): headers = { - "Authorization": "token {token}".format(token=token), - "Accept": "application/vnd.github.v3+json", + "Authorization": "Bearer {token}".format(token=token), + "Accept": "application/vnd.github+json", } url = REPOS_URL.format(org=org) click.echo("Retrieving repos at {}".format(url)) From c9c934b3438af459f6a27b14072050f5c177c16d Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Wed, 26 Oct 2022 15:52:19 -0600 Subject: [PATCH 19/28] Update delete.py --- github_deploy/commands/delete.py | 46 +------------------------------- 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/github_deploy/commands/delete.py b/github_deploy/commands/delete.py index 8ead88e..11742df 100644 --- a/github_deploy/commands/delete.py +++ b/github_deploy/commands/delete.py @@ -5,51 +5,7 @@ from github_deploy.commands._constants import BASE_URL from github_deploy.commands._http_utils import delete, get, list_repos -from github_deploy.commands._utils import get_repo - - -async def delete_content( - *, - session, - repo, - dest, - token, - semaphore, - exists, - current_sha, -): - headers = { - "Authorization": "token {token}".format(token=token), - "Accept": "application/vnd.github.v3+json", - } - - data = {"message": "Deleted {}".format(dest)} - if exists: - data["sha"] = current_sha - - url = BASE_URL.format(repo=repo, path=dest) - - async with semaphore: - response = await delete( - session=session, url=url, data=data, headers=headers - ) - - return response - - -async def check_exists(*, session, repo, dest, token, semaphore, skip_missing): - headers = {"Authorization": "token {token}".format(token=token)} - url = BASE_URL.format(repo=repo, path=dest) - - async with semaphore: - response = await get( - session=session, - url=url, - headers=headers, - skip_missing=skip_missing, - ) - - return response +from github_deploy.commands._utils import get_repo, delete_contents, check_exists async def handle_file_delete(*, repo, dest, token, semaphore, session): From a0e1ffd7058bc221e174feaf17bc3c58e6784f74 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Wed, 26 Oct 2022 15:52:58 -0600 Subject: [PATCH 20/28] Update delete.py --- github_deploy/commands/delete.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github_deploy/commands/delete.py b/github_deploy/commands/delete.py index 11742df..d3c2d50 100644 --- a/github_deploy/commands/delete.py +++ b/github_deploy/commands/delete.py @@ -4,8 +4,8 @@ import asyncclick as click from github_deploy.commands._constants import BASE_URL -from github_deploy.commands._http_utils import delete, get, list_repos -from github_deploy.commands._utils import get_repo, delete_contents, check_exists +from github_deploy.commands._http_utils import delete, get, list_repos, delete_contents, check_exists +from github_deploy.commands._utils import get_repo async def handle_file_delete(*, repo, dest, token, semaphore, session): From d8700bac284d6181abf95e72719ea04543eb1556 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Wed, 26 Oct 2022 15:54:17 -0600 Subject: [PATCH 21/28] Update _http_utils.py --- github_deploy/commands/_http_utils.py | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/github_deploy/commands/_http_utils.py b/github_deploy/commands/_http_utils.py index 2cb9ae2..0dd699d 100644 --- a/github_deploy/commands/_http_utils.py +++ b/github_deploy/commands/_http_utils.py @@ -62,3 +62,47 @@ async def list_repos(*, session, org, token): click.echo("Retrieving repos at {}".format(url)) response = await get(session=session, url=url, headers=headers) return response + + +async def delete_content( + *, + session, + repo, + dest, + token, + semaphore, + exists, + current_sha, +): + headers = { + "Authorization": "Bearer {token}".format(token=token), + "Accept": "application/vnd.github+json", + } + + data = {"message": "Deleted {}".format(dest)} + if exists: + data["sha"] = current_sha + + url = BASE_URL.format(repo=repo, path=dest) + + async with semaphore: + response = await delete( + session=session, url=url, data=data, headers=headers + ) + + return response + + +async def check_exists(*, session, repo, dest, token, semaphore, skip_missing): + headers = {"Authorization": "Bearer {token}".format(token=token)} + url = BASE_URL.format(repo=repo, path=dest) + + async with semaphore: + response = await get( + session=session, + url=url, + headers=headers, + skip_missing=skip_missing, + ) + + return response From e9cedafca476c69ae7af4b82def339981760c89d Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 28 Oct 2022 08:06:37 -0600 Subject: [PATCH 22/28] chore: reformatted and restructured modules --- github_deploy/commands/_http_utils.py | 60 +---------------- github_deploy/commands/_repo_utils.py | 93 +++++++++++++++++++++++++++ github_deploy/commands/_utils.py | 7 ++ github_deploy/commands/delete.py | 3 +- github_deploy/commands/upload.py | 65 +------------------ 5 files changed, 103 insertions(+), 125 deletions(-) create mode 100644 github_deploy/commands/_repo_utils.py diff --git a/github_deploy/commands/_http_utils.py b/github_deploy/commands/_http_utils.py index 0dd699d..539b9ec 100644 --- a/github_deploy/commands/_http_utils.py +++ b/github_deploy/commands/_http_utils.py @@ -1,9 +1,6 @@ import ssl -import certifi - -import asyncclick as click -from github_deploy.commands._constants import REPOS_URL +import certifi async def get(*, session, url, headers=None, skip_missing=False): @@ -51,58 +48,3 @@ async def delete(*, session, url, data, headers=None): ) as response: value = await response.json() return value - - -async def list_repos(*, session, org, token): - headers = { - "Authorization": "Bearer {token}".format(token=token), - "Accept": "application/vnd.github+json", - } - url = REPOS_URL.format(org=org) - click.echo("Retrieving repos at {}".format(url)) - response = await get(session=session, url=url, headers=headers) - return response - - -async def delete_content( - *, - session, - repo, - dest, - token, - semaphore, - exists, - current_sha, -): - headers = { - "Authorization": "Bearer {token}".format(token=token), - "Accept": "application/vnd.github+json", - } - - data = {"message": "Deleted {}".format(dest)} - if exists: - data["sha"] = current_sha - - url = BASE_URL.format(repo=repo, path=dest) - - async with semaphore: - response = await delete( - session=session, url=url, data=data, headers=headers - ) - - return response - - -async def check_exists(*, session, repo, dest, token, semaphore, skip_missing): - headers = {"Authorization": "Bearer {token}".format(token=token)} - url = BASE_URL.format(repo=repo, path=dest) - - async with semaphore: - response = await get( - session=session, - url=url, - headers=headers, - skip_missing=skip_missing, - ) - - return response diff --git a/github_deploy/commands/_repo_utils.py b/github_deploy/commands/_repo_utils.py new file mode 100644 index 0000000..ac6c068 --- /dev/null +++ b/github_deploy/commands/_repo_utils.py @@ -0,0 +1,93 @@ +import base64 + +import aiofiles +import asyncclick as click + +from github_deploy.commands._constants import REPOS_URL, BASE_URL +from github_deploy.commands._http_utils import get, delete, put +from github_deploy.commands._utils import get_headers + + +async def list_repos(*, session, org, token): + url = REPOS_URL.format(org=org) + click.echo("Retrieving repos at {}".format(url)) + response = await get(session=session, url=url, headers=get_headers(token=token)) + return response + + +async def delete_content( + *, + session, + repo, + dest, + token, + semaphore, + exists, + current_sha, +): + data = {"message": "Deleted {}".format(dest)} + if exists: + data["sha"] = current_sha + + url = BASE_URL.format(repo=repo, path=dest) + + async with semaphore: + response = await delete( + session=session, url=url, data=data, headers=get_headers(token=token) + ) + + return response + + +async def check_exists(*, session, repo, dest, token, semaphore, skip_missing): + url = BASE_URL.format(repo=repo, path=dest) + + async with semaphore: + response = await get( + session=session, + url=url, + headers=get_headers(token=token), + skip_missing=skip_missing, + ) + + return response + + +async def upload_content( + *, + session, + repo, + source, + dest, + token, + semaphore, + exists, + current_sha, + current_content +): + async with semaphore: + async with aiofiles.open(source, mode="rb") as f: + output = await f.read() + base64_content = base64.b64encode(output).decode("ascii") + + if current_content == base64_content: + click.echo("Skipping: Contents are the same.") + return + + data = { + "message": "Updated {}".format(dest) + if exists + else "Added {}".format(dest), + "content": base64_content, + } + if exists: + data["sha"] = current_sha + + url = BASE_URL.format(repo=repo, path=dest) + + async with semaphore: + response = await put( + session=session, url=url, data=data, headers=get_headers(token=token) + ) + + return response diff --git a/github_deploy/commands/_utils.py b/github_deploy/commands/_utils.py index 109bd3f..3289654 100644 --- a/github_deploy/commands/_utils.py +++ b/github_deploy/commands/_utils.py @@ -8,3 +8,10 @@ def can_upload(*, repo, include_private): if include_private and repo["private"] is True else not repo["private"] ) + + +def get_headers(*, token): + return { + "Authorization": "Bearer {token}".format(token=token), + "Accept": "application/vnd.github+json", + } diff --git a/github_deploy/commands/delete.py b/github_deploy/commands/delete.py index d3c2d50..9cafec6 100644 --- a/github_deploy/commands/delete.py +++ b/github_deploy/commands/delete.py @@ -3,8 +3,7 @@ import aiohttp import asyncclick as click -from github_deploy.commands._constants import BASE_URL -from github_deploy.commands._http_utils import delete, get, list_repos, delete_contents, check_exists +from github_deploy.commands._repo_utils import list_repos, delete_content, check_exists from github_deploy.commands._utils import get_repo diff --git a/github_deploy/commands/upload.py b/github_deploy/commands/upload.py index fe58e6d..3baf4a3 100644 --- a/github_deploy/commands/upload.py +++ b/github_deploy/commands/upload.py @@ -1,75 +1,12 @@ import asyncio -import base64 -import aiofiles import aiohttp import asyncclick as click -from github_deploy.commands._constants import BASE_URL -from github_deploy.commands._http_utils import put, list_repos, get +from github_deploy.commands._repo_utils import list_repos, check_exists, upload_content from github_deploy.commands._utils import get_repo, can_upload -async def upload_content( - *, - session, - repo, - source, - dest, - token, - semaphore, - exists, - current_sha, - current_content -): - headers = { - "Authorization": "token {token}".format(token=token), - "Accept": "application/vnd.github.v3+json", - } - - async with semaphore: - async with aiofiles.open(source, mode="rb") as f: - output = await f.read() - base64_content = base64.b64encode(output).decode("ascii") - - if current_content == base64_content: - click.echo("Skipping: Contents are the same.") - return - - data = { - "message": "Updated {}".format(dest) - if exists - else "Added {}".format(dest), - "content": base64_content, - } - if exists: - data["sha"] = current_sha - - url = BASE_URL.format(repo=repo, path=dest) - - async with semaphore: - response = await put( - session=session, url=url, data=data, headers=headers - ) - - return response - - -async def check_exists(*, session, repo, dest, token, semaphore, skip_missing): - headers = {"Authorization": "token {token}".format(token=token)} - url = BASE_URL.format(repo=repo, path=dest) - - async with semaphore: - response = await get( - session=session, - url=url, - headers=headers, - skip_missing=skip_missing, - ) - - return response - - async def handle_file_upload( *, repo, source, dest, overwrite, token, semaphore, session ): From 1742c2d98774c57bc57a4f6059113a203d0f253d Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 28 Oct 2022 08:16:15 -0600 Subject: [PATCH 23/28] re-order imports --- github_deploy/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/github_deploy/main.py b/github_deploy/main.py index c7cce59..246c985 100644 --- a/github_deploy/main.py +++ b/github_deploy/main.py @@ -1,6 +1,7 @@ -import asyncclick as click import os +import asyncclick as click + plugin_folder = os.path.join(os.path.dirname(__file__), "commands") From d360ac3d702b753b6d08f217a17e332d82304146 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 28 Oct 2022 08:32:03 -0600 Subject: [PATCH 24/28] Update dependabot.yml --- .github/dependabot.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index afb98ae..ae760f7 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,7 +1,12 @@ version: 2 updates: -- package-ecosystem: github-actions - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 + - package-ecosystem: github-actions + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 + - package-ecosystem: pip + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 From e52d6685555b2ace63aaaaf2c98cc03146966d86 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 28 Oct 2022 08:33:59 -0600 Subject: [PATCH 25/28] Update Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2904151..ef3339f 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ release: dist ## package and upload a release @twine upload dist/* dist: clean install-deploy ## builds source and wheel package - @pip install twine==3.4.1 + @pip install twine @python setup.py sdist bdist_wheel increase-version: guard-PART ## Increase project version From 7bebc153d4076034cabd1019341a8e41cd2a410f Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 28 Oct 2022 08:41:15 -0600 Subject: [PATCH 26/28] Updated build target --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ef3339f..ca6e713 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ release: dist ## package and upload a release dist: clean install-deploy ## builds source and wheel package @pip install twine - @python setup.py sdist bdist_wheel + @python -m build increase-version: guard-PART ## Increase project version @bump2version $(PART) From 64bdf4846dd79c82b091243da4d79b86e1773031 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 28 Oct 2022 09:02:36 -0600 Subject: [PATCH 27/28] chore: upgrade required python version to 3.7 --- .github/workflows/deploy.yml | 2 +- github_deploy/commands/_repo_utils.py | 8 ++++---- github_deploy/commands/_utils.py | 4 ++-- github_deploy/commands/delete.py | 4 ++-- github_deploy/main.py | 2 +- setup.py | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 43ab2a6..b02f205 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -19,7 +19,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: '3.6.x' + python-version: '3.7.x' - name: Upgrade pip run: pip install -U pip diff --git a/github_deploy/commands/_repo_utils.py b/github_deploy/commands/_repo_utils.py index ac6c068..438d970 100644 --- a/github_deploy/commands/_repo_utils.py +++ b/github_deploy/commands/_repo_utils.py @@ -10,7 +10,7 @@ async def list_repos(*, session, org, token): url = REPOS_URL.format(org=org) - click.echo("Retrieving repos at {}".format(url)) + click.echo(f"Retrieving repos at {url}") response = await get(session=session, url=url, headers=get_headers(token=token)) return response @@ -25,7 +25,7 @@ async def delete_content( exists, current_sha, ): - data = {"message": "Deleted {}".format(dest)} + data = {"message": f"Deleted {dest}"} if exists: data["sha"] = current_sha @@ -75,9 +75,9 @@ async def upload_content( return data = { - "message": "Updated {}".format(dest) + "message": f"Updated {dest}" if exists - else "Added {}".format(dest), + else f"Added {dest}", "content": base64_content, } if exists: diff --git a/github_deploy/commands/_utils.py b/github_deploy/commands/_utils.py index 3289654..afc4b79 100644 --- a/github_deploy/commands/_utils.py +++ b/github_deploy/commands/_utils.py @@ -1,5 +1,5 @@ def get_repo(*, org, project): - return "{org}/{project}".format(project=project, org=org) + return f"{org}/{project}" def can_upload(*, repo, include_private): @@ -12,6 +12,6 @@ def can_upload(*, repo, include_private): def get_headers(*, token): return { - "Authorization": "Bearer {token}".format(token=token), + "Authorization": f"Bearer {token}", "Accept": "application/vnd.github+json", } diff --git a/github_deploy/commands/delete.py b/github_deploy/commands/delete.py index 9cafec6..9b7209e 100644 --- a/github_deploy/commands/delete.py +++ b/github_deploy/commands/delete.py @@ -51,7 +51,7 @@ async def handle_file_delete(*, repo, dest, token, semaphore, session): ) return click.style( - "No content found at {repo}/{dest}".format(repo=repo, dest=dest), + f"No content found at {repo}/{dest}", fg="blue", bold=True, ) @@ -100,7 +100,7 @@ async def main(org, token, dest): ) click.echo( click.style( - 'Deleting "{path}" for all repositories:'.format(path=dest), + f'Deleting "{dest}" for all repositories:', fg="blue", ) ) diff --git a/github_deploy/main.py b/github_deploy/main.py index 246c985..c93ad51 100644 --- a/github_deploy/main.py +++ b/github_deploy/main.py @@ -28,7 +28,7 @@ def get_command(self, ctx, name): eval(code, ns, ns) return ns["main"] - ctx.fail("Invalid Command \"{name}\"".format(name=name)) + ctx.fail(f"Invalid Command \"{name}\"") main = GithubDeploy( diff --git a/setup.py b/setup.py index 5369b06..b8719f4 100644 --- a/setup.py +++ b/setup.py @@ -45,7 +45,7 @@ author_email="jtonye@ymail.com", license="MIT", packages=find_packages(), - python_requires=">=3.6", + python_requires=">=3.7", extras_require=extras_require, install_requires=[ "asyncclick", From 6d810b26a0531069b5cad139338a85082d39ff6a Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 28 Oct 2022 09:39:14 -0600 Subject: [PATCH 28/28] Updated Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ca6e713..b7e4461 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ release: dist ## package and upload a release @twine upload dist/* dist: clean install-deploy ## builds source and wheel package - @pip install twine + @pip install build twine @python -m build increase-version: guard-PART ## Increase project version