Browse Source

ref(now): Use now.sh Github app env vars for banner (#17591)

Evan Purkhiser 5 years ago
parent
commit
f38ae0a369
2 changed files with 17 additions and 22 deletions
  1. 12 18
      src/sentry/static/sentry/app/actionCreators/deployPreview.jsx
  2. 5 4
      webpack.config.js

+ 12 - 18
src/sentry/static/sentry/app/actionCreators/deployPreview.jsx

@@ -10,31 +10,25 @@ export function displayDeployPreviewAlert() {
     return;
   }
 
-  const {commitRef, reviewId, repoUrl} = DEPLOY_PREVIEW_CONFIG;
-  const repoName = repoUrl?.match(/\w+\/\w+\/?$/)[0];
+  const {branch, commitSha, githubOrg, githubRepo} = DEPLOY_PREVIEW_CONFIG;
+  const repoUrl = `https://github.com/${githubOrg}/${githubRepo}`;
 
-  if (!repoName) {
-    return;
-  }
-
-  const pullLink = (
-    <ExternalLink href={`${repoUrl}/pull/${reviewId}`}>
-      {t('%s#%s', repoName, reviewId)}
+  const commitLink = (
+    <ExternalLink href={`${repoUrl}/commit/${commitSha}`}>
+      {t('%s@%s', `${githubOrg}/${githubRepo}`, commitSha.slice(0, 6))}
     </ExternalLink>
   );
 
-  const sha = (
-    <ExternalLink href={`${repoUrl}/commit/${commitRef}`}>
-      @{commitRef.slice(0, 6)}
-    </ExternalLink>
+  const branchLink = (
+    <ExternalLink href={`${repoUrl}/tree/${branch}`}>{branch}</ExternalLink>
   );
 
   AlertActions.addAlert({
-    message: tct('You are viewing a frontend deploy preview of [pullLink] ([sha])', {
-      pullLink,
-      sha,
-    }),
-    type: 'info',
+    message: tct(
+      'You are viewing a frontend deploy preview of [commitLink] ([branchLink])',
+      {commitLink, branchLink}
+    ),
+    type: 'warning',
     neverExpire: true,
   });
 }

+ 5 - 4
webpack.config.js

@@ -52,10 +52,11 @@ const SHOULD_HOT_MODULE_RELOAD = DEV_MODE && !!env.SENTRY_UI_HOT_RELOAD;
 
 // Deploy previews are built using zeit. We can check if we're in zeit's
 // build process by checking the existence of the PULL_REQUEST env var.
-const DEPLOY_PREVIEW_CONFIG = env.PULL_REQUEST && {
-  commitRef: env.COMMIT_REF,
-  reviewId: env.REVIEW_ID,
-  repoUrl: env.REPOSITORY_URL,
+const DEPLOY_PREVIEW_CONFIG = env.NOW_GITHUB_DEPLOYMENT && {
+  branch: env.NOW_GITHUB_COMMIT_REF,
+  commitSha: env.NOW_GITHUB_COMMIT_SHA,
+  githubOrg: env.NOW_GITHUB_COMMIT_ORG,
+  githubRepo: env.NOW_GITHUB_COMMIT_REPO,
 };
 
 // When deploy previews are enabled always enable experimental SPA mode --