Skip to content

Commit 704028b

Browse files
authored
Merge pull request #3 from pinanks/DOT-883
2 parents 9b337d6 + 3ec6fc0 commit 704028b

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed

commands/utils/dom.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const path = require('path')
44
const formData = require('form-data');
55
const { JSDOM } = require("jsdom");
66
var { constants } = require('./constants');
7+
const { getLastCommit } = require('./git')
78

89
async function sendDoM(storybookUrl, stories, storybookConfig, options) {
910
const createBrowser = require('browserless')
@@ -38,16 +39,23 @@ async function sendDoM(storybookUrl, stories, storybookConfig, options) {
3839
}
3940
await browser.close()
4041

41-
// Send html files to the renderer API
42+
// Create form
43+
let commit = await getLastCommit();
4244
const form = new formData();
4345
for (const [storyId, storyInfo] of Object.entries(stories)) {
4446
const file = fs.readFileSync('doms/' + storyId + '.html');
45-
form.append('html', file, storyInfo.kind + ': ' + storyInfo.name + '.html');
47+
form.append('files', file, storyInfo.kind + ': ' + storyInfo.name + '.html');
4648
}
4749
form.append('resolution', storybookConfig.resolutions);
4850
form.append('browser', storybookConfig.browsers);
4951
form.append('projectToken', process.env.PROJECT_TOKEN);
5052
form.append('buildName', options.buildname);
53+
form.append('branch', commit.branch);
54+
form.append('commitId', commit.shortHash);
55+
form.append('commitAuthor', commit.author.name);
56+
form.append('commitMessage', commit.subject);
57+
58+
// Send DOM to render API
5159
axios.post(constants[options.env].RENDER_API_URL, form, {
5260
headers: {
5361
...form.getHeaders()

commands/utils/git.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const cp = require('child_process');
2+
3+
function executeCommand(command, options) {
4+
let dst = process.cwd()
5+
6+
if(!!options && options.dst) {
7+
dst = options.dst
8+
}
9+
10+
try {
11+
return cp.execSync(command, {
12+
cwd: dst,
13+
stdio: ['ignore', 'pipe', 'ignore'],
14+
encoding: 'utf-8'
15+
});
16+
} catch (error) {
17+
return '';
18+
}
19+
}
20+
21+
async function getLastCommit(options) {
22+
const splitCharacter = '<##>';
23+
const prettyFormat = ["%h", "%H", "%s", "%f", "%b", "%at", "%ct", "%an", "%ae", "%cn", "%ce", "%N", ""];
24+
const command = 'git log -1 --pretty=format:"' + prettyFormat.join(splitCharacter) + '"' +
25+
' && git rev-parse --abbrev-ref HEAD' +
26+
' && git tag --contains HEAD'
27+
28+
res = executeCommand(command, options);
29+
res = res.split(splitCharacter);
30+
31+
// e.g. master\n or master\nv1.1\n or master\nv1.1\nv1.2\n
32+
var branchAndTags = res[res.length-1].split('\n').filter(n => n);
33+
var branch = branchAndTags[0];
34+
var tags = branchAndTags.slice(1);
35+
36+
return {
37+
shortHash: res[0] || '',
38+
hash: res[1] || '',
39+
subject: res[2] || '',
40+
sanitizedSubject: res[3] || '',
41+
body: res[4] || '',
42+
authoredOn: res[5] || '',
43+
committedOn: res[6] || '',
44+
author: {
45+
name: res[7] || '',
46+
email: res[8] || '',
47+
},
48+
committer: {
49+
name: res[9] || '',
50+
email: res[10] || ''
51+
},
52+
notes: res[11] || '',
53+
branch: branch || '',
54+
tags: tags || []
55+
};
56+
}
57+
58+
module.exports = { getLastCommit }

index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ configCommand.command('create')
2525
program.command('storybook')
2626
.description('Snapshot Storybook stories')
2727
.argument('<url>', 'Storybook url')
28-
.requiredOption('--buildname <string>', 'Build name')
2928
.option('-c --config <file>', 'Config file path')
3029
// .option('--env <prod|stage>', 'Runtime environment option', 'prod')
3130
.action(async function(url, options) {

0 commit comments

Comments
 (0)