Skip to content

Commit

Permalink
fix: should work with master or production branches now
Browse files Browse the repository at this point in the history
  • Loading branch information
kamranayub authored Jul 31, 2020
2 parents 270b856 + 2a69ae0 commit 324e205
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"files.eol": "\n"
}
8 changes: 6 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1838,14 +1838,18 @@ const run = async () => {
// not the *latest commit* of the PR which is what Netlify uses. Instead,
// have to use github.context.payload.pull_request.head.sha
// See: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#pull_request
const commitSha = github.context.payload.pull_request.head.sha;
const isPr = 'pull_request' in github.context.payload;
const commitSha = isPr ? github.context.payload.pull_request.head.sha : github.context.sha;
const MAX_TIMEOUT = Number(core.getInput('max_timeout')) || 60;
const siteName = core.getInput('site_name');
if (!netlifyToken) {
core.setFailed('Please set NETLIFY_TOKEN env variable to your Netlify Personal Access Token secret');
}

if (!commitSha) {
core.setFailed('Could not determine GitHub commit');
} else {
console.log('Using SHA', commitSha, isPr ? 'from PR' : '');
}
if (!siteName) {
core.setFailed('Required field `site_name` was not provided');
Expand All @@ -1867,7 +1871,7 @@ const run = async () => {
// Most likely, it's the first entry in the response
// but we correlate it just to be safe
const commitDeployment = netlifyDeployments.find(
(d) => d.commit_ref === commitSha && d.context === 'deploy-preview',
(d) => d.commit_ref === commitSha && d.context === (isPr ? 'deploy-preview' : 'production'),
);
if (!commitDeployment) {
core.setFailed(`Could not find deployment for commit ${commitSha}`);
Expand Down
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@ const run = async () => {
// not the *latest commit* of the PR which is what Netlify uses. Instead,
// have to use github.context.payload.pull_request.head.sha
// See: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#pull_request
const commitSha = github.context.payload.pull_request.head.sha;
const isPr = 'pull_request' in github.context.payload;
const commitSha = isPr ? github.context.payload.pull_request.head.sha : github.context.sha;
const MAX_TIMEOUT = Number(core.getInput('max_timeout')) || 60;
const siteName = core.getInput('site_name');
if (!netlifyToken) {
core.setFailed('Please set NETLIFY_TOKEN env variable to your Netlify Personal Access Token secret');
}

if (!commitSha) {
core.setFailed('Could not determine GitHub commit');
} else {
console.log('Using SHA', commitSha, isPr ? 'from PR' : '');
}
if (!siteName) {
core.setFailed('Required field `site_name` was not provided');
Expand All @@ -61,7 +65,7 @@ const run = async () => {
// Most likely, it's the first entry in the response
// but we correlate it just to be safe
const commitDeployment = netlifyDeployments.find(
(d) => d.commit_ref === commitSha && d.context === 'deploy-preview',
(d) => d.commit_ref === commitSha && d.context === (isPr ? 'deploy-preview' : 'production'),
);
if (!commitDeployment) {
core.setFailed(`Could not find deployment for commit ${commitSha}`);
Expand Down
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,12 @@
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"pre-commit": "lint-staged && npm run build && git add dist",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"lint-staged": {
"./*.js": [
"eslint --cache --fix",
"npm run build"
],
"./*.js": "eslint --cache --fix",
"*.md": "prettier --write"
},
"release": {
Expand Down

0 comments on commit 324e205

Please sign in to comment.