Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
43e4d41
Add docstrings for the constants module
ocket8888 Mar 2, 2022
8ed319f
Fix linting issues in __main__ module
ocket8888 Mar 2, 2022
bfe7a36
Fix importing internal PyGitHub variable
ocket8888 Mar 2, 2022
e66d5bf
Fix accessing private member of a class
ocket8888 Mar 2, 2022
a4676b9
Remove unused import
ocket8888 Mar 2, 2022
2084ed4
Make milestone url non-optional
ocket8888 Mar 2, 2022
8cac94d
Wrap long line, un-sentence-ify Exception text
ocket8888 Mar 2, 2022
74cf861
Cover unit test case with doctest
ocket8888 Mar 2, 2022
cb22f0f
Fix the get_major_version test
ocket8888 Mar 2, 2022
3210f5e
Add docstrings
ocket8888 Mar 2, 2022
1d1ee74
Remove unnecessary 'f' modifier
ocket8888 Mar 2, 2022
12c5865
Fix passing unnecessary explicit option-argument
ocket8888 Mar 2, 2022
eae669e
Fix required ENV_FILE environment variable is unset
ocket8888 Mar 2, 2022
3ae8b87
Add running the doctests when module is executed
ocket8888 Mar 2, 2022
c0c0c1e
Separate release note parsing from fetching and add tests
ocket8888 Mar 2, 2022
b0f10fd
Fix release notes-parsing unit test
ocket8888 Mar 2, 2022
ac0f1f9
Separate fetching latest Go version from parsing response for testing
ocket8888 Mar 2, 2022
64f365f
Unexport things that don't need to be exported
ocket8888 Mar 2, 2022
3e86967
Remove trivially inferrable types
ocket8888 Mar 2, 2022
bbd3878
Fix not stripping whitespace from repo go version
ocket8888 Mar 2, 2022
c614163
remove extraneous path separator
ocket8888 Mar 3, 2022
5453d9b
Remove unimported type decoration
ocket8888 Mar 3, 2022
fa512a8
Fix using incorrect Milestone URL.
ocket8888 Mar 3, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/actions/pr-to-update-go/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ To run the unit tests:
.. code-block:: shell

python3 -m unittest discover ./tests

To run the doctests:

.. code-block:: shell

python3 ./pr_to_update_go/go_pr_maker.py
23 changes: 18 additions & 5 deletions .github/actions/pr-to-update-go/pr_to_update_go/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""
A utility for automatically updating Go. For full usage information, refer to
the action's README.rst file.

Options
--update-version-only Exit after updating GO_VERSION file.
"""
import os
import sys
from argparse import ArgumentParser, Namespace
Expand All @@ -21,17 +28,23 @@


def main() -> None:
"""
The entrypoint for running the PR-maker.
"""
parser = ArgumentParser()
parser.add_argument('--update-version-only', type=bool, default=False, help='Exit after updating the GO_VERSION file')
parser.add_argument(
'--update-version-only',
action="store_true",
help='Exit after updating the GO_VERSION file'
)
args: Namespace = parser.parse_args()

try:
github_token: str = os.environ[ENV_GITHUB_TOKEN]
github_token = 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(args.update_version_only)

gh_api = Github(login_or_token=github_token)
GoPRMaker(gh_api).run(args.update_version_only)

main()
74 changes: 74 additions & 0 deletions .github/actions/pr-to-update-go/pr_to_update_go/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,88 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""
The constants module holds some constants used by the PR maker.

Environment variable names, and the meanings of the values of those variables:

ENV_GIT_AUTHOR_NAME - The username of the author for commits
ENV_GITHUB_REPOSITORY - The "name" of the repository set by GHA (e.g. octocat/Hello-World)
ENV_GITHUB_REPOSITORY_OWNER - The repository owner's name set by GHA (e.g. octocat)
ENV_GITHUB_TOKEN - The token used to access the GitHub API - set by GHA
ENV_GO_VERSION_FILE - The repository-relative path to the file containing the Go version
ENV_ENV_FILE - The repository-relative path to an environment file containing
a line setting the variable GO_VERSION to the Go version
(e.g. GO_VERSION=3.2.1)

Miscellaneous:

GIT_AUTHOR_EMAIL_TEMPLATE - Template used to construct the Git Author's email address.
GO_REPO_NAME - The name of the official Go repository.
GO_VERSION_URL - A URL from which information about Go releases is fetched.
RELEASE_PAGE_URL - The URL of a webpage containing changelog notes about Go releases.
"""
from typing import Final

ENV_GIT_AUTHOR_NAME: Final = 'GIT_AUTHOR_NAME'
"""
The name of the environment variable set to username of the author for commits.
"""

ENV_GITHUB_REPOSITORY: Final = 'GITHUB_REPOSITORY'
"""
The name of the environment variable set to "name" of the repository set by GHA
(e.g. octocat/Hello-World).
"""

ENV_GITHUB_REPOSITORY_OWNER: Final = 'GITHUB_REPOSITORY_OWNER'
"""
The name of the environment variable set to repository owner's name set by GHA
(e.g. octocat).
"""

ENV_GITHUB_TOKEN: Final = 'GITHUB_TOKEN'
"""
The name of the environment variable set to token used to access the GitHub
API - set by GHA.
"""

ENV_GO_VERSION_FILE: Final = 'GO_VERSION_FILE'
"""
The name of the environment variable set to repository-relative path to the file
containing the Go version.
"""

ENV_ENV_FILE: Final = 'ENV_FILE'
"""
The name of the environment variable set to repository-relative path to an
environment file containing a line setting the variable GO_VERSION to the Go
version (e.g. GO_VERSION=3.2.1).
"""


GIT_AUTHOR_EMAIL_TEMPLATE: Final = '{git_author_name}@users.noreply.github.com'
"""Template used to construct the Git Author's email address."""

GO_REPO_NAME: Final = 'golang/go'
"""The name of the official Go repository."""

GO_VERSION_URL: Final = 'https://golang.org/dl/?mode=json'
"""A URL from which information about Go releases is fetched."""

RELEASE_PAGE_URL: Final = 'https://golang.org/doc/devel/release.html'
"""The URL of a webpage containing changelog notes about Go releases."""


__all__ = [
"ENV_GIT_AUTHOR_NAME",
"ENV_GITHUB_REPOSITORY",
"ENV_GITHUB_REPOSITORY_OWNER",
"ENV_GITHUB_TOKEN",
"ENV_GO_VERSION_FILE",
"ENV_ENV_FILE",
"GIT_AUTHOR_EMAIL_TEMPLATE",
"GO_REPO_NAME",
"GO_VERSION_URL",
"RELEASE_PAGE_URL",
]
Loading