Skip to content

Commit b5dedb0

Browse files
committed
GITHUB_API_URL
#583
1 parent 0c5b1bc commit b5dedb0

File tree

19 files changed

+56
-25
lines changed

19 files changed

+56
-25
lines changed

services/cli/src/bencher/sub/project/run/ci/github_actions.rs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const GITHUB_ACTIONS: &str = "GITHUB_ACTIONS";
1111
const GITHUB_EVENT_PATH: &str = "GITHUB_EVENT_PATH";
1212
const GITHUB_EVENT_NAME: &str = "GITHUB_EVENT_NAME";
1313
const GITHUB_SHA: &str = "GITHUB_SHA";
14+
const GITHUB_API_URL: &str = "GITHUB_API_URL";
1415
const GITHUB_STEP_SUMMARY: &str = "GITHUB_STEP_SUMMARY";
1516

1617
const PULL_REQUEST: &str = "pull_request";
@@ -74,6 +75,8 @@ pub enum GitHubError {
7475
BadFullName(String),
7576
#[error("GitHub Action event repository full name is not of the form `owner/repo`: ({0})")]
7677
InvalidFullName(String),
78+
#[error("Failed to parse GitHub API URL: {0}")]
79+
BaseUri(octocrab::Error),
7780
#[error("Failed to authenticate as GitHub Action: {0}")]
7881
Auth(octocrab::Error),
7982
#[error("Failed to list GitHub PR comments: {0}")]
@@ -203,7 +206,7 @@ impl GitHubActions {
203206
docker_env(GITHUB_EVENT_NAME)
204207
);
205208
return self
206-
.create_github_check(report_comment, &event_str, &event)
209+
.create_github_check(report_comment, log, &event_str, &event)
207210
.await;
208211
};
209212

@@ -227,6 +230,7 @@ impl GitHubActions {
227230
async fn create_github_check(
228231
&self,
229232
report_comment: &ReportComment,
233+
log: bool,
230234
event_str: &str,
231235
event: &serde_json::Value,
232236
) -> Result<(), GitHubError> {
@@ -247,8 +251,12 @@ impl GitHubActions {
247251
annotations: Vec::new(),
248252
images: Vec::new(),
249253
};
250-
let check = Octocrab::builder()
251-
.user_access_token(self.token.clone())
254+
255+
let mut builder = Octocrab::builder().user_access_token(self.token.clone());
256+
if let Some(url) = github_api_url(log) {
257+
builder = builder.base_uri(url).map_err(GitHubError::BaseUri)?;
258+
}
259+
let check = builder
252260
.build()
253261
.map_err(GitHubError::Auth)?
254262
.checks(owner, repo)
@@ -286,10 +294,11 @@ impl GitHubActions {
286294
let full_name = repository_full_name(event_str, event)?;
287295
let (owner, repo) = split_full_name(full_name)?;
288296

289-
let github_client = Octocrab::builder()
290-
.user_access_token(self.token.clone())
291-
.build()
292-
.map_err(GitHubError::Auth)?;
297+
let mut builder = Octocrab::builder().user_access_token(self.token.clone());
298+
if let Some(url) = github_api_url(log) {
299+
builder = builder.base_uri(url).map_err(GitHubError::BaseUri)?;
300+
}
301+
let github_client = builder.build().map_err(GitHubError::Auth)?;
293302

294303
// Get the comment ID if it exists
295304
let comment_id = get_comment(
@@ -419,3 +428,16 @@ fn is_permissions_error(err: &octocrab::Error) -> bool {
419428
err.to_string()
420429
.contains("Resource not accessible by integration")
421430
}
431+
432+
fn github_api_url(log: bool) -> Option<String> {
433+
if let Ok(url) = std::env::var(GITHUB_API_URL) {
434+
Some(url)
435+
} else {
436+
cli_eprintln_quietable!(
437+
log,
438+
"Failed to get GitHub API URL, defaulting to `https://api.github.com`\n{}",
439+
docker_env(GITHUB_API_URL)
440+
);
441+
None
442+
}
443+
}

services/console/src/chunks/docs-explanation/bencher-run/de/github-actions.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ In jedem Fall werden die Ergebnisse auch zur Zusammenfassung des Jobs hinzugefü
1818
> - `GITHUB_ACTIONS`
1919
> - `GITHUB_EVENT_NAME`
2020
> - `GITHUB_EVENT_PATH`
21-
> - `GITHUB_SHA`
21+
> - `GITHUB_SHA`
22+
> - `GITHUB_API_URL` (GitHub Enterprise Server nur)

services/console/src/chunks/docs-explanation/bencher-run/en/github-actions.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ In either case, the results will also be added to the job summary.
1818
> - `GITHUB_ACTIONS`
1919
> - `GITHUB_EVENT_NAME`
2020
> - `GITHUB_EVENT_PATH`
21-
> - `GITHUB_SHA`
21+
> - `GITHUB_SHA`
22+
> - `GITHUB_API_URL` (GitHub Enterprise Server only)

services/console/src/chunks/docs-explanation/bencher-run/es/github-actions.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ En cualquier caso, los resultados también se agregarán al resumen del trabajo.
1818
> - `GITHUB_ACTIONS`
1919
> - `GITHUB_EVENT_NAME`
2020
> - `GITHUB_EVENT_PATH`
21-
> - `GITHUB_SHA`
21+
> - `GITHUB_SHA`
22+
> - `GITHUB_API_URL` (GitHub Enterprise Server solamente)

services/console/src/chunks/docs-explanation/bencher-run/fr/github-actions.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ Dans les deux cas, les résultats seront également ajoutés au résumé du trav
1818
> - `GITHUB_ACTIONS`
1919
> - `GITHUB_EVENT_NAME`
2020
> - `GITHUB_EVENT_PATH`
21-
> - `GITHUB_SHA`
21+
> - `GITHUB_SHA`
22+
> - `GITHUB_API_URL` (GitHub Enterprise Server uniquement)

services/console/src/chunks/docs-explanation/bencher-run/ja/github-actions.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
> - `GITHUB_ACTIONS`
1818
> - `GITHUB_EVENT_NAME`
1919
> - `GITHUB_EVENT_PATH`
20-
> - `GITHUB_SHA`
20+
> - `GITHUB_SHA`
21+
> - `GITHUB_API_URL` (GitHub Enterprise Server のみ)

services/console/src/chunks/docs-explanation/bencher-run/ko/github-actions.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
> - `GITHUB_ACTIONS`
1919
> - `GITHUB_EVENT_NAME`
2020
> - `GITHUB_EVENT_PATH`
21-
> - `GITHUB_SHA`
21+
> - `GITHUB_SHA`
22+
> - `GITHUB_API_URL` (GitHub Enterprise Server 전용)

services/console/src/chunks/docs-explanation/bencher-run/pt/github-actions.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ Em ambos os casos, os resultados também serão adicionados ao resumo do trabalh
1818
> - `GITHUB_ACTIONS`
1919
> - `GITHUB_EVENT_NAME`
2020
> - `GITHUB_EVENT_PATH`
21-
> - `GITHUB_SHA`
21+
> - `GITHUB_SHA`
22+
> - `GITHUB_API_URL` (GitHub Enterprise Server apenas)

services/console/src/chunks/docs-explanation/bencher-run/ru/github-actions.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
> - `GITHUB_ACTIONS`
1212
> - `GITHUB_EVENT_NAME`
1313
> - `GITHUB_EVENT_PATH`
14-
> - `GITHUB_SHA`
14+
> - `GITHUB_SHA`
15+
> - `GITHUB_API_URL` (GitHub Enterprise Server только)

services/console/src/chunks/docs-explanation/bencher-run/zh/github-actions.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
> - `GITHUB_ACTIONS`
1212
> - `GITHUB_EVENT_NAME`
1313
> - `GITHUB_EVENT_PATH`
14-
> - `GITHUB_SHA`
14+
> - `GITHUB_SHA`
15+
> - `GITHUB_API_URL` (GitHub Enterprise Server 专用)

0 commit comments

Comments
 (0)