Merge "Add login callback in case of 403 Forbidden response from jenkins"
diff --git a/web/fetcher.ts b/web/fetcher.ts
index ea2873c..6c4c723 100644
--- a/web/fetcher.ts
+++ b/web/fetcher.ts
@@ -89,17 +89,19 @@
}
const checkRuns: CheckRun[] = [];
for (const jenkins of this.configs) {
- // TODO: Requests to Jenkins should be proxied through the Gerrit backend
- // to avoid CORS requests.
- await this.fetchFromJenkins(
- `${jenkins.url}/gerrit-checks/runs?change=${changeData.changeNumber}&patchset=${changeData.patchsetNumber}`
- )
- .then(response => response.json())
- .then(data => {
- data.runs.forEach((run: JenkinsCheckRun) => {
- checkRuns.push(this.convert(run));
- });
- });
+ const checks_url = `${jenkins.url}/gerrit-checks/runs?change=${changeData.changeNumber}&patchset=${changeData.patchsetNumber}`;
+ const response = await this.fetchFromJenkins(checks_url);
+ if (response.status === 403) {
+ // Give the user a LOGIN button that will open a new tab where they can log into Jenkins
+ return {
+ responseCode: ResponseCode.NOT_LOGGED_IN,
+ loginCallback: () => window.open(jenkins.url),
+ };
+ }
+ const data = await response.json();
+ data.runs.forEach((run: JenkinsCheckRun) => {
+ checkRuns.push(this.convert(run));
+ });
}
return {