Skip to content

Commit c2eca50

Browse files
Revert "[BazelBot] Use a Machine User (llvm#794)"
This reverts commit 3919ae8. After discussion with the infra area team, it turns out an app would be preferred here despite the issues with the actual commit email.
1 parent 0158188 commit c2eca50

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

google-bazel-bot/bazel-bot/bazelbot_server_test.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ def test_parse_targets(self):
2525
"BUILDKITE_API_TOKEN": "bk_token",
2626
"GITHUB_APP_ID": "app_id",
2727
"GITHUB_APP_PRIVATE_KEY": "private_key",
28-
"GITHUB_PR_PAT": "pr_pat",
28+
"GITHUB_PR_APP_ID": "pr_app_id",
29+
"GITHUB_PR_APP_PRIVATE_KEY": "pr_private_key",
2930
},
3031
)
3132
def test_credential_manager(self):
@@ -35,16 +36,14 @@ def test_credential_manager(self):
3536
self.assertEqual(creds.bk_token, "bk_token")
3637
self.assertEqual(creds.gh_fork_repo_name, "fork_user/llvm-project")
3738
self.assertEqual(creds.gh_pr_repo_name, "pr_user/llvm-project")
38-
self.assertEqual(creds.gh_pr_pat, "pr_pat")
39+
self.assertEqual(creds.gh_pr_app_id, "pr_app_id")
40+
self.assertEqual(creds.gh_pr_app_private_key, "pr_private_key")
3941

4042
@mock.patch("utils.git.Repo")
4143
@mock.patch("utils.github.GithubIntegration")
42-
@mock.patch("utils.github.Github")
4344
@mock.patch("utils.github.Auth")
4445
@mock.patch("os.path.exists")
45-
def test_local_git_repo(
46-
self, mock_exists, github_integration_mock, github_mock, auth_mock, mock_repo
47-
):
46+
def test_local_git_repo(self, mock_exists, github_mock, auth_mock, mock_repo):
4847
mock_exists.return_value = False
4948
creds = mock.MagicMock()
5049
creds.gh_fork_repo_name = "fork/repo"

google-bazel-bot/bazel-bot/utils.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def __init__(self):
3535
self.bk_token = os.getenv("BUILDKITE_API_TOKEN")
3636
self.gh_app_id = os.getenv("GITHUB_APP_ID")
3737
self.gh_app_private_key = os.getenv("GITHUB_APP_PRIVATE_KEY")
38-
self.gh_pr_pat = os.getenv("GITHUB_PR_PAT")
38+
self.gh_pr_app_id = os.getenv("GITHUB_PR_APP_ID")
39+
self.gh_pr_app_private_key = os.getenv("GITHUB_PR_APP_PRIVATE_KEY")
3940

4041
@property
4142
def gh_fork_repo_name(self):
@@ -198,9 +199,17 @@ def __init__(self, repo_path: str, creds: CredentialManager, can_create_pr):
198199
self.creds.gh_fork_repo_name
199200
)
200201
)
201-
self.gh_pr_repo = github.Github(
202-
auth=github.Auth.Token(self.creds.gh_pr_pat)
203-
).get_repo(self.creds.gh_pr_repo_name)
202+
self.pr_github_integration = github.GithubIntegration(
203+
auth=github.Auth.AppAuth(creds.gh_pr_app_id, creds.gh_pr_app_private_key)
204+
)
205+
self.gh_pr_installation = self.pr_github_integration.get_repo_installation(
206+
self.creds.gh_pr_user, "llvm-project"
207+
)
208+
self.gh_pr_repo = (
209+
self.gh_pr_installation.get_github_for_installation().get_repo(
210+
self.creds.gh_pr_repo_name
211+
)
212+
)
204213
self.bazel_utils_path = os.path.join(self.repo_path, "utils", "bazel")
205214
self.main_branch = "main"
206215
self.remote_name = "origin"

google-bazel-bot/bazel-fixer-bot.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,16 @@ spec:
4242
secretKeyRef:
4343
name: github-app
4444
key: private-key
45-
- name: GITHUB_PR_PAT
45+
- name: GITHUB_PR_APP_ID
4646
valueFrom:
4747
secretKeyRef:
4848
name: github-pr-app
49-
key: pat
49+
key: id
50+
- name: GITHUB_PR_APP_PRIVATE_KEY
51+
valueFrom:
52+
secretKeyRef:
53+
name: github-pr-app
54+
key: private-key
5055
- name: GITHUB_FORK_USER
5156
value: google-bazel-bot
5257
- name: GITHUB_PR_USER

google-bazel-bot/main.tf

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,12 @@ data "google_secret_manager_secret_version" "github_app_private_key" {
148148
secret = "github-app-private-key"
149149
}
150150

151-
data "google_secret_manager_secret_version" "github_pr_pat" {
152-
secret = "github-pr-pat"
151+
data "google_secret_manager_secret_version" "github_pr_app_id" {
152+
secret = "github-pr-app-id"
153+
}
154+
155+
data "google_secret_manager_secret_version" "github_pr_app_private_key" {
156+
secret = "github-pr-app-private-key"
153157
}
154158

155159
resource "kubernetes_namespace" "bazel_ci" {
@@ -194,7 +198,8 @@ resource "kubernetes_secret" "github_pr_app" {
194198
}
195199

196200
data = {
197-
"pat" = data.google_secret_manager_secret_version.github_pr_pat.secret_data
201+
"id" = data.google_secret_manager_secret_version.github_pr_app_id.secret_data
202+
"private-key" = data.google_secret_manager_secret_version.github_pr_app_private_key.secret_data
198203
}
199204

200205
type = "Opaque"

0 commit comments

Comments
 (0)