ocket8888 commented on a change in pull request #5506: URL: https://github.com/apache/trafficcontrol/pull/5506#discussion_r573398237
########## File path: .github/actions/pr-to-update-go/README.rst ########## @@ -0,0 +1,73 @@ +.. +.. +.. Licensed under the Apache License, Version 2.0 (the "License"); +.. you may not use this file except in compliance with the License. +.. You may obtain a copy of the License at +.. +.. http://www.apache.org/licenses/LICENSE-2.0 +.. +.. Unless required by applicable law or agreed to in writing, software +.. distributed under the License is distributed on an "AS IS" BASIS, +.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +.. See the License for the specific language governing permissions and +.. limitations under the License. +.. + +*************** +pr-to-update-go +*************** + +Opens a PR if a new minor Go revision is available. + +For example, it will open a PR if the ``GO_VERSION`` contains ``1.14.7`` but Go versions 1.15.1 and 1.14.8 are available, it will + +1. Create a branch named ``go-1.14.8`` to update the repo's Go version to 1.14.8 +2. Open a PR targeting the ``master`` branch from branch ``go-1.14.8`` Review comment: Sentence structure here is a little repetitious: "it will open a PR if (condition), it will... [open a PR]" ########## File path: .github/actions/pr-to-update-go/README.rst ########## @@ -0,0 +1,73 @@ +.. +.. +.. Licensed under the Apache License, Version 2.0 (the "License"); +.. you may not use this file except in compliance with the License. +.. You may obtain a copy of the License at +.. +.. http://www.apache.org/licenses/LICENSE-2.0 +.. +.. Unless required by applicable law or agreed to in writing, software +.. distributed under the License is distributed on an "AS IS" BASIS, +.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +.. See the License for the specific language governing permissions and +.. limitations under the License. +.. + +*************** +pr-to-update-go +*************** + +Opens a PR if a new minor Go revision is available. + +For example, it will open a PR if the ``GO_VERSION`` contains ``1.14.7`` but Go versions 1.15.1 and 1.14.8 are available, it will + +1. Create a branch named ``go-1.14.8`` to update the repo's Go version to 1.14.8 +2. Open a PR targeting the ``master`` branch from branch ``go-1.14.8`` + +Other behavior in this scenario: + +- If a branch named ``go-1.14.8`` already exists, no additional branch is created. +- If a PR titled *Update Go version to 1.14.8* already exists, no additional PR is opened. + +Environment Variables +===================== + ++----------------------------+----------------------------------------------------------------------------------+ +| Environment Variable Name | Value | ++============================+==================================================================================+ +| ``GIT_AUTHOR_NAME`` | Optional. The username to associate with the commit that updates the Go version. | ++----------------------------+----------------------------------------------------------------------------------+ +| ``GITHUB_TOKEN`` | Required. ``${{ github.token }}`` or ``${{ secrets.GITHUB_TOKEN }}`` | ++----------------------------+----------------------------------------------------------------------------------+ +| ``GO_VERSION_FILE`` | Required. The file in the repo containing the version of Go used by the repo. | ++----------------------------+----------------------------------------------------------------------------------+ + + +Outputs +======= + +``exit-code`` +------------- + +Exit code is 0 unless an error was encountered. + +Example usage +============= + +.. code-block:: yaml + + - name: PR to Update Go + run: python3 -m pr_to_update_go + env: + GIT_AUTHOR_NAME: asfgit + GITHUB_TOKEN: ${{ github.token }} + GO_VERSION_FILE: GO_VERSION + +Tests +===== + +To run the unit tests: + +.. code-block:: shell + + python3 -m unittest discover ./tests Review comment: I believe you need a blank line at the end of a code block for Sphinx to parse it properly. However, GitHub's renderer isn't Sphinx. I think it's just standard RST - and the `code-block` directive is provided by Sphinx, so if the intention was for this to be readable on GitHub I don't think it'll work. ########## File path: .github/actions/pr-to-update-go/pr_to_update_go/__main__.py ########## @@ -0,0 +1,32 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +import sys + +from github.MainClass import Github + +from pr_to_update_go.GoPRMaker import GoPRMaker +from pr_to_update_go.constants import ENV_GITHUB_TOKEN + + +def main() -> None: + try: + github_token: str = os.environ[ENV_GITHUB_TOKEN] + except KeyError: + print(f'Environment variable {ENV_GITHUB_TOKEN} must be defined.') + sys.exit(1) + gh = Github(login_or_token=github_token) + GoPRMaker(gh).run() + + +main() Review comment: I _think_ this should be wrapped in an `if __name__ == "__main__":` but I could be wrong; I'm not entirely sure the interpreter sets `__name__` like that when the module is called with `python -m`. It's not normal to import modules beginning with `_` from packages - and nothing is meant to use this - so it could be safe, but it damages my delicate sensibilities to have large routines running as side effects to importing a module. ########## File path: .github/actions/pr-to-update-go/pr_to_update_go/GoPRMaker.py ########## @@ -0,0 +1,210 @@ +#!/usr/bin/env python3 +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import json +import os +import re +import requests +import sys + +from github.InputGitAuthor import InputGitAuthor +from github.Label import Label +from requests import Response + +from github.Branch import Branch +from github.GithubException import BadCredentialsException, GithubException, UnknownObjectException +from github.MainClass import Github +from github.Milestone import Milestone +from github.PaginatedList import PaginatedList +from github.PullRequest import PullRequest +from github.Repository import Repository + +from pr_to_update_go.constants import ENV_GITHUB_TOKEN, GO_VERSION_URL, ENV_GITHUB_REPOSITORY, \ + ENV_GITHUB_REPOSITORY_OWNER, GO_REPO_NAME, RELEASE_PAGE_URL, ENV_GO_VERSION_FILE, ENV_GIT_AUTHOR_NAME, \ + GIT_AUTHOR_EMAIL_TEMPLATE + + +class GoPRMaker: + gh: Github + latest_go_version: str + repo: Repository + + def __init__(self, gh: Github) -> None: + self.gh = gh + repo_name: str = self.get_repo_name() + self.repo = self.get_repo(repo_name) + + def run(self) -> None: Review comment: This is just my two cents, but if a function doesn't return an explicit value it's fine to just leave it without a return type. I'm not sure our Pylint config cares, but to me a lack of return type is "void". ########## File path: .github/actions/pr-to-update-go/pr_to_update_go/pr_template.md ########## @@ -0,0 +1,120 @@ +<!-- +************ STOP!! ************ +If this Pull Request is intended to fix a security vulnerability, DO NOT submit it! Instead, contact +the Apache Software Foundation Security Team at [email protected] and follow the +guidelines at https://www.apache.org/security/ regarding vulnerability disclosure. +--> +## What does this PR (Pull Request) do? +<!-- Explain the changes you made here. If this fixes an Issue, identify it by +replacing the text in the checkbox item with the Issue number e.g. + +- [x] This PR fixes #9001 OR is not related to any Issue + +^ This will automatically close Issue number 9001 when the Pull Request is +merged (The '#' is important). + +Be sure you check the box properly, see the "The following criteria are ALL +met by this PR" section for details. +--> Review comment: I don't think you need comments like these, they're for humans to read ########## File path: .github/actions/pr-to-update-go/setup.cfg ########## @@ -0,0 +1,37 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +[metadata] +name = pr-to-update-go +version = 0.0.0 +description = Opens a PR if a new minor Go revision is available. +long_description = file: README.rst +long_description_content_type = text/x-rst +author = Apache Traffic Control +author_email = [email protected] +classifiers = OSI Approved :: Apache Software License + +[options] +python_requires = >=3.9 +packages = pr_to_update_go +install_requires = + PyGithub + requests + +[options.entry_points] +console_scripts = pr-to-update-go = pr_to_update_go:main + +[options.extras_require] +test = unittest + +[options.package_data] +pr_to_update_go = pr_template.md Review comment: Setuptools will read this in lieu of passing the info as args? That's pretty neat. Wonder how long that's been the case. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
