Skip to content

Commit

Permalink
Fix source version (#1)
Browse files Browse the repository at this point in the history
use pr sha instead of context sha
  • Loading branch information
arielj authored Dec 1, 2021
1 parent b4e1360 commit 049d05d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 30 deletions.
35 changes: 21 additions & 14 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9144,15 +9144,17 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__nccwpck_require__(2186));
const github = __importStar(__nccwpck_require__(5438));
const HerokuClient = __nccwpck_require__(504);
core.debug(JSON.stringify(github.context));
const ctx = github.context;
const pr = ctx.payload.pull_request;
const fork = pr.head.repo.fork;
const branch = pr.head.ref;
const version = ctx.sha;
const version = pr.head.sha;
const pr_number = pr.number;
const repo_url = ctx.payload.repository.html_url;
const source_url = `${repo_url}/tarball/${branch}`;
const action = core.getInput("action");
const pipeline = process.env.HEROKU_PIPELINE_ID;
function run() {
return __awaiter(this, void 0, void 0, function* () {
if (fork) {
Expand All @@ -9173,15 +9175,14 @@ function run() {
}
switch (action) {
case "destroy":
core.info("Fetching review app list");
core.info("Fetching Review Apps list");
try {
const reviewApps = yield heroku.get(`/pipelines/${process.env.HEROKU_PIPELINE_ID}/review-apps`);
// Get the Review App for this PR
const reviewApps = yield heroku.get(`/pipelines/${pipeline}/review-apps`);
const app = reviewApps.find((app) => app.pr_number == pr_number);
if (app) {
core.info("Deleting review app");
core.info("Destroying Review App");
yield heroku.delete(`/review-apps/${app.id}`);
core.info("Review app deleted");
core.info("Review App destroyed");
}
}
catch (error) {
Expand All @@ -9191,22 +9192,29 @@ function run() {
break;
case "create":
try {
core.info("Creating review app");
yield heroku.post("/review-apps", {
core.info("Creating Review App");
core.debug(JSON.stringify({
branch,
pipeline,
source_blob: {
url: source_url,
version,
},
pr_number,
}));
const response = yield heroku.post("/review-apps", {
body: {
branch,
pipeline: process.env.HEROKU_PIPELINE_ID,
pipeline,
source_blob: {
url: source_url,
version,
},
pr_number,
environment: {
GIT_REPO_URL: repo_url,
},
},
});
core.info("Created review app");
core.debug(response);
core.info("Review App created");
}
catch (error) {
core.error(JSON.stringify(error));
Expand All @@ -9216,7 +9224,6 @@ function run() {
core.debug("Invalid action, no action was performed, use one of 'create' or 'destroy'");
break;
}
core.info("Action completed");
});
}
run();
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

39 changes: 24 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ interface ReviewApp {
id: number;
}

core.debug(JSON.stringify(github.context));

const ctx = github.context;
const pr = ctx.payload.pull_request!;
const fork = pr.head.repo.fork;
const branch = pr.head.ref;
const version = ctx.sha;
const version = pr.head.sha;
const pr_number = pr.number;
const repo_url = ctx.payload!.repository!.html_url;
const source_url = `${repo_url}/tarball/${branch}`;
const action = core.getInput("action");
const pipeline = process.env.HEROKU_PIPELINE_ID;

async function run() {
if (fork) {
Expand All @@ -41,18 +44,17 @@ async function run() {

switch (action) {
case "destroy":
core.info("Fetching review app list");
core.info("Fetching Review Apps list");
try {
const reviewApps: ReviewApp[] = await heroku.get(
`/pipelines/${process.env.HEROKU_PIPELINE_ID}/review-apps`
`/pipelines/${pipeline}/review-apps`
);

// Get the Review App for this PR
const app = reviewApps.find((app) => app.pr_number == pr_number);
if (app) {
core.info("Deleting review app");
core.info("Destroying Review App");
await heroku.delete(`/review-apps/${app.id}`);
core.info("Review app deleted");
core.info("Review App destroyed");
}
} catch (error) {
core.error(JSON.stringify(error));
Expand All @@ -62,22 +64,31 @@ async function run() {
break;
case "create":
try {
core.info("Creating review app");
await heroku.post("/review-apps", {
body: {
core.info("Creating Review App");
core.debug(
JSON.stringify({
branch,
pipeline: process.env.HEROKU_PIPELINE_ID,
pipeline,
source_blob: {
url: source_url,
version,
},
pr_number,
environment: {
GIT_REPO_URL: repo_url,
})
);
const response = await heroku.post("/review-apps", {
body: {
branch,
pipeline,
source_blob: {
url: source_url,
version,
},
pr_number,
},
});
core.info("Created review app");
core.debug(response);
core.info("Review App created");
} catch (error) {
core.error(JSON.stringify(error));
}
Expand All @@ -89,8 +100,6 @@ async function run() {
);
break;
}

core.info("Action completed");
}

run();

0 comments on commit 049d05d

Please sign in to comment.