mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:20:11 +01:00
Bazel-ify most of the Python scripts. (#229)
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
# Exceptions. See /LICENSE for license information.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
|
||||
|
||||
py_library(
|
||||
name = "github_helpers",
|
||||
srcs = ["github_helpers.py"],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "github_helpers_test",
|
||||
srcs = ["github_helpers_test.py"],
|
||||
deps = [":github_helpers"],
|
||||
)
|
||||
|
||||
py_binary(
|
||||
name = "pr_comments",
|
||||
srcs = ["pr_comments.py"],
|
||||
deps = ["github_helpers"],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "pr_comments_test",
|
||||
srcs = ["pr_comments_test.py"],
|
||||
deps = [":pr_comments"],
|
||||
)
|
||||
|
||||
py_binary(
|
||||
name = "update_label_access",
|
||||
srcs = ["update_label_access.py"],
|
||||
deps = ["github_helpers"],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "update_label_access_test",
|
||||
srcs = ["update_label_access_test.py"],
|
||||
deps = [
|
||||
":pr_comments",
|
||||
":update_label_access",
|
||||
],
|
||||
)
|
||||
@@ -9,9 +9,3 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
Scripts for use with GitHub.
|
||||
|
||||
See individual scripts for more details.
|
||||
|
||||
Please use `pytest` for testing:
|
||||
|
||||
```
|
||||
$ pip install pytest
|
||||
```
|
||||
|
||||
@@ -9,7 +9,7 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from github_tools import github_helpers
|
||||
from carbon.github_tools import github_helpers
|
||||
|
||||
|
||||
_TEST_QUERY = """
|
||||
|
||||
@@ -12,15 +12,21 @@ import argparse
|
||||
import datetime
|
||||
import hashlib
|
||||
import os
|
||||
import sys
|
||||
import importlib.util
|
||||
import textwrap
|
||||
|
||||
# To support direct runs, ensure the pythonpath has the repo root.
|
||||
_PYTHONPATH = os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))
|
||||
if _PYTHONPATH not in sys.path:
|
||||
sys.path.insert(0, _PYTHONPATH)
|
||||
|
||||
from github_tools import github_helpers
|
||||
# Do some extra work to support direct runs.
|
||||
try:
|
||||
from carbon.github_tools import github_helpers
|
||||
except ImportError:
|
||||
github_helpers_spec = importlib.util.spec_from_file_location(
|
||||
"github_helpers",
|
||||
os.path.join(os.path.dirname(__file__), "github_helpers.py"),
|
||||
)
|
||||
github_helpers = importlib.util.module_from_spec(github_helpers_spec)
|
||||
github_helpers_spec.loader.exec_module(github_helpers)
|
||||
|
||||
|
||||
# The main query, into which other queries are composed.
|
||||
_QUERY = """
|
||||
|
||||
@@ -10,10 +10,15 @@ import os
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from github_tools import pr_comments
|
||||
from carbon.github_tools import github_helpers
|
||||
from carbon.github_tools import pr_comments
|
||||
|
||||
|
||||
class TestPRComments(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# Stub out the access token.
|
||||
os.environ[github_helpers._ENV_TOKEN] = "unused"
|
||||
|
||||
def test_format_comment_short(self):
|
||||
created_at = "2001-02-03T04:05:06Z"
|
||||
self.assertEqual(
|
||||
|
||||
Executable → Regular
+2
-11
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""Updates the contributors-with-label-access team.
|
||||
|
||||
This team exists because we need a team to manage triage access to repos;
|
||||
@@ -14,25 +12,18 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
# https://github.com/PyGithub/PyGithub
|
||||
# GraphQL is preferred, but falling back to pygithub for unsupported mutations.
|
||||
import github
|
||||
|
||||
# To support direct runs, ensure the pythonpath has the repo root.
|
||||
_PYTHONPATH = os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))
|
||||
if _PYTHONPATH not in sys.path:
|
||||
sys.path.insert(0, _PYTHONPATH)
|
||||
|
||||
from github_tools import github_helpers
|
||||
from carbon.github_tools import github_helpers
|
||||
|
||||
# The organization to mirror members from.
|
||||
_ORG = "carbon-language"
|
||||
|
||||
# The team to mirror to.
|
||||
_TEAM = "contributors-with-label-access"
|
||||
_TEAM = "contributors"
|
||||
|
||||
# Accounts in the org to skip mirroring.
|
||||
_IGNORE_ACCOUNTS = ("CarbonLangInfra", "google-admin", "googlebot")
|
||||
|
||||
@@ -6,16 +6,21 @@ Exceptions. See /LICENSE for license information.
|
||||
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
"""
|
||||
|
||||
import github
|
||||
import os
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from github_tools import github_helpers
|
||||
from github_tools import update_label_access
|
||||
import github
|
||||
|
||||
from carbon.github_tools import github_helpers
|
||||
from carbon.github_tools import update_label_access
|
||||
|
||||
|
||||
class TestUpdateLabelAccess(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# Stub out the access token.
|
||||
os.environ[github_helpers._ENV_TOKEN] = "unused"
|
||||
|
||||
self.client = mock.create_autospec(github_helpers.Client, instance=True)
|
||||
self.gh = mock.create_autospec(github.Github, instance=True)
|
||||
self.gh_org = mock.create_autospec(github.Organization, instance=True)
|
||||
|
||||
Reference in New Issue
Block a user