Skip to content

Commit 740d8b5

Browse files
authoredApr 4, 2020
fix: branch is undefined (#33)
* fix: branch is undefined
1 parent 22abc96 commit 740d8b5

File tree

307 files changed

+125885
-12662
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

307 files changed

+125885
-12662
lines changed
 

‎CHANGELOG.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## [v2.0.1](https://github.com/amondnet/now-deployment/tree/v2.0.1) (2020-02-25)
44

5-
[Full Changelog](https://github.com/amondnet/now-deployment/compare/v2.0.0...v2.0.1)
5+
[Full Changelog](https://github.com/amondnet/now-deployment/compare/v2...v2.0.1)
66

77
**Fixed bugs:**
88

@@ -24,13 +24,16 @@
2424

2525
**Implemented enhancements:**
2626

27-
- Support for Now CLI v17 [\#24](https://github.com/amondnet/now-deployment/issues/24)
2827
- Do not want to receive comments from action [\#14](https://github.com/amondnet/now-deployment/issues/14)
28+
- Support for Now CLI v17 [\#24](https://github.com/amondnet/now-deployment/issues/24)
2929
- feat: now cli v17, add `NOW\_PROJECT\_ID` and `NOW\_ORG\_ID` env variable [\#26](https://github.com/amondnet/now-deployment/pull/26) ([amondnet](https://github.com/amondnet))
3030

31-
**Closed issues:**
31+
**Fixed bugs:**
3232

3333
- Deploy stalled [\#23](https://github.com/amondnet/now-deployment/issues/23)
34+
35+
**Closed issues:**
36+
3437
- Can I upload the contents of a folder with pre-built assets? [\#22](https://github.com/amondnet/now-deployment/issues/22)
3538
- getting 403 error every time it tries to comment [\#18](https://github.com/amondnet/now-deployment/issues/18)
3639
- Feature: Ability to specify path for --local-config flag [\#16](https://github.com/amondnet/now-deployment/issues/16)

‎index.js

+43-12
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,41 @@ if (githubToken) {
2020
}
2121

2222
async function run() {
23+
core.debug(`action : ${context.action}`);
24+
core.debug(`ref : ${context.ref}`);
25+
core.debug(`eventName : ${context.eventName}`);
26+
core.debug(`actor : ${context.actor}`);
27+
core.debug(`sha : ${context.sha}`);
28+
core.debug(`workflow : ${context.workflow}`);
29+
let ref = context.ref;
30+
let sha = context.sha;
2331
await setEnv();
24-
const deploymentUrl = await nowDeploy();
32+
33+
let commit = execSync("git log -1 --pretty=format:%B")
34+
.toString()
35+
.trim();
36+
if (github.context.eventName === 'push') {
37+
const pushPayload = github.context.payload;
38+
core.debug(`The head commit is: ${pushPayload.head_commit}`);
39+
} else if ( github.context.eventName === 'pull_request') {
40+
const pullRequestPayload = github.context.payload;
41+
core.debug(`head : ${pullRequestPayload.pull_request.head}`);
42+
43+
ref = pullRequestPayload.pull_request.head.ref;
44+
sha = pullRequestPayload.pull_request.head.sha;
45+
core.debug(`The head ref is: ${pullRequestPayload.pull_request.head.ref}`);
46+
core.debug(`The head sha is: ${pullRequestPayload.pull_request.head.sha}`);
47+
48+
if ( octokit ) {
49+
const { data: commitData } = await octokit.git.getCommit({
50+
...context.repo, commit_sha: sha
51+
});
52+
commit = commitData.message;
53+
core.debug(`The head commit is: ${commit}`);
54+
}
55+
}
56+
57+
const deploymentUrl = await nowDeploy(ref, commit);
2558
if (deploymentUrl) {
2659
core.info("set preview-url output");
2760
core.setOutput("preview-url", deploymentUrl);
@@ -31,10 +64,10 @@ async function run() {
3164
if (githubComment && githubToken) {
3265
if (context.issue.number) {
3366
core.info("this is related issue or pull_request ");
34-
await createCommentOnPullRequest(deploymentCommit, deploymentUrl);
67+
await createCommentOnPullRequest(sha, deploymentUrl);
3568
} else if (context.eventName === "push") {
3669
core.info("this is push event");
37-
await createCommentOnCommit(deploymentCommit, deploymentUrl);
70+
await createCommentOnCommit(sha, deploymentUrl);
3871
}
3972
} else {
4073
core.info("comment : disabled");
@@ -53,11 +86,7 @@ async function setEnv() {
5386
}
5487
}
5588

56-
async function nowDeploy() {
57-
const commit = execSync("git log -1 --pretty=format:%B")
58-
.toString()
59-
.trim();
60-
89+
async function nowDeploy(ref, commit) {
6190
let myOutput = "";
6291
let myError = "";
6392
const options = {};
@@ -99,7 +128,9 @@ async function nowDeploy() {
99128
"-m",
100129
`githubCommitRepo=${context.repo.repo}`,
101130
"-m",
102-
`githubCommitMessage=${commit}`
131+
`githubCommitMessage=${commit}`,
132+
"-m",
133+
`githubCommitRef=${ref}`
103134
],
104135
options
105136
);
@@ -165,15 +196,15 @@ async function createCommentOnPullRequest(deploymentCommit, deploymentUrl) {
165196
return;
166197
}
167198
const commentId = await findPreviousComment(
168-
"Deploy preview for _website_ ready!"
199+
"This pull request is being automatically deployed with"
169200
);
170201

171202
const commentBody = stripIndents`
172-
Deploy preview for _website_ ready!
203+
This pull request is being automatically deployed with [now-deployment](https://github.com/amondnet/now-deployment)
173204
174205
Built with commit ${deploymentCommit}
175206
176-
https://${deploymentUrl}
207+
✅ Preview: ${deploymentUrl}
177208
`;
178209

179210
if (commentId) {

1 commit comments

Comments
 (1)

github-actions[bot] commented on Apr 4, 2020

@github-actions[bot]
Please sign in to comment.