Skip to content

Commit ebab6ae

Browse files
committed
Initial Commit
0 parents  commit ebab6ae

5 files changed

Lines changed: 205 additions & 0 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
coverage/
3+
npm-debug.log
4+
.env

.jscsrc

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"disallowImplicitTypeConversion": ["string"],
3+
"disallowSpaceBeforeBinaryOperators": [","],
4+
"disallowSpaceAfterBinaryOperators": ["!"],
5+
"disallowKeywords": ["with"],
6+
"disallowKeywordsOnNewLine": ["else"],
7+
"disallowMultipleLineBreaks": true,
8+
"disallowMultipleVarDecl": true,
9+
"disallowSpaceBeforePostfixUnaryOperators": true,
10+
"disallowMixedSpacesAndTabs": true,
11+
"disallowTrailingComma": true,
12+
"disallowYodaConditions": true,
13+
"disallowEmptyBlocks": true,
14+
"disallowQuotedKeysInObjects": "allButReserved",
15+
"disallowSpaceAfterPrefixUnaryOperators": true,
16+
"disallowSpaceAfterObjectKeys": true,
17+
"disallowSpacesInsideParentheses": true,
18+
"disallowSpacesInsideArrayBrackets": "all",
19+
"disallowTrailingWhitespace": true,
20+
"disallowSpacesInFunctionExpression": {
21+
"beforeOpeningRoundBrace": true
22+
},
23+
"disallowSpacesInNamedFunctionExpression": {
24+
"beforeOpeningRoundBrace": true
25+
},
26+
"disallowSpacesInAnonymousFunctionExpression": {
27+
"beforeOpeningRoundBrace": true
28+
},
29+
"disallowSpacesInFunctionDeclaration": {
30+
"beforeOpeningRoundBrace": true
31+
},
32+
"maximumLineLength": 120,
33+
"requireSpacesInFunctionExpression": {
34+
"beforeOpeningCurlyBrace": true
35+
},
36+
"requireBlocksOnNewline": true,
37+
"requireCapitalizedConstructors": true,
38+
"requireCurlyBraces": ["if", "else", "for", "while", "do", "try", "catch"],
39+
"requireDotNotation": true,
40+
"requireFunctionDeclarations": true,
41+
"requireLineFeedAtFileEnd": true,
42+
"requireSpaceBeforeBinaryOperators": ["?", "+", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
43+
"requireSpaceAfterBinaryOperators": ["?", "+", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
44+
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try"],
45+
"requirePaddingNewLinesInObjects": true,
46+
"requirePaddingNewLinesAfterBlocks": true,
47+
"requirePaddingNewLinesBeforeLineComments": true,
48+
"requireParenthesesAroundIIFE": true,
49+
"requireSpacesInConditionalExpression": true,
50+
"requireCommaBeforeLineBreak": true,
51+
"requireSpaceBeforeBlockStatements": true,
52+
"validateIndentation": 2,
53+
"validateJSDoc": {
54+
"checkParamNames": true,
55+
"requireParamTypes": true
56+
},
57+
"validateQuoteMarks": {
58+
"mark": "'",
59+
"escape": true
60+
}
61+
}

.jshintrc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"node": true,
3+
"bitwise": true,
4+
"curly": true,
5+
"eqeqeq": true,
6+
"immed": true,
7+
"indent": 2,
8+
"latedef": "func",
9+
"loopfunc": true,
10+
"newcap": true,
11+
"noarg": true,
12+
"nonbsp": true,
13+
"nonew": true,
14+
"regexp": true,
15+
"undef": true,
16+
"unused": true,
17+
"strict": true,
18+
"undef": true,
19+
"unused": true,
20+
"trailing": true
21+
}

package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "visualtesting-service-stash",
3+
"version": "0.0.1",
4+
"description": "Stash service plugin for VisualTesting",
5+
"main": "stash.js",
6+
"dependencies": {
7+
"chai": "^2.2.0",
8+
"superagent": "^1.1.0",
9+
"superagent-as-promised": "^3.1.1"
10+
},
11+
"devDependencies": {
12+
"coveralls": "^2.11.2",
13+
"istanbul": "^0.3.13",
14+
"jscs": "^1.12.0",
15+
"jshint": "^2.6.3",
16+
"mocha": "^2.2.1",
17+
"mocha-sinon": "^1.1.4",
18+
"sinon": "^1.14.1"
19+
}
20+
}

stash.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
'use strict';
2+
3+
var assert = require('chai').assert;
4+
var request = require('superagent');
5+
require('superagent-as-promised')(request);
6+
7+
function verifyConfig(config) {
8+
assert.isObject(config);
9+
assert.equal(config.name, StashService.prototype.serviceKey);
10+
11+
assert.isObject(config.options);
12+
var optionKeys = Object.keys(config.options);
13+
assert.equal(optionKeys.length, 1);
14+
var optionKey = optionKeys[0];
15+
16+
if (optionKey === 'user') {
17+
assert.isString(config.options[optionKey].user);
18+
assert.isString(config.options[optionKey].repository);
19+
} else if (optionKey === 'project') {
20+
assert.isString(config.options[optionKey].project);
21+
assert.isString(config.options[optionKey].repository);
22+
} else {
23+
assert(false, 'Expected stash repo type to be a user or a project');
24+
}
25+
}
26+
27+
function StashService(options) {
28+
assert.isObject(options);
29+
assert.isString(options.url);
30+
assert.isString(options.user);
31+
assert.isString(options.password);
32+
33+
this._serviceConfig = options;
34+
}
35+
36+
StashService.prototype = {
37+
serviceKey: 'stash',
38+
39+
setBuildStatus: function(config, options) {
40+
verifyConfig(config);
41+
42+
assert.isObject(options);
43+
assert.isString(options.sha);
44+
assert.include(['pending', 'success', 'failure'], options.status);
45+
46+
var state;
47+
48+
switch (options.status) {
49+
case 'pending':
50+
state = 'INPROGRESS';
51+
break;
52+
case 'success':
53+
state = 'SUCCESSFUL';
54+
break;
55+
case 'failure':
56+
state = 'FAILED';
57+
break;
58+
}
59+
60+
return request
61+
.post(this._serviceConfig.url + '/rest/build-status/1.0/commits/' + options.sha)
62+
.auth(this._serviceConfig.user, this._serviceConfig.password)
63+
.send({
64+
state: state,
65+
key: 'CI - Visual',
66+
name: 'CI - Visual',
67+
url: 'http://google.com'
68+
});
69+
},
70+
71+
addComment: function(config, options) {
72+
verifyConfig(config);
73+
74+
assert.isObject(options);
75+
assert.isString(options.sha);
76+
assert.isString(options.comment);
77+
78+
var projectKey;
79+
var repository;
80+
if (config.options.user) {
81+
projectKey = '~' + config.options.user.user;
82+
repository = config.options.user.repository;
83+
} else {
84+
projectKey = config.options.project.project;
85+
repository = config.options.project.repository;
86+
}
87+
88+
var url = '/rest/api/1.0/projects/' + projectKey + '/repos/' + repository + '/commits/' + options.sha + '/comments';
89+
90+
return request
91+
.post(this._serviceConfig.url + url)
92+
.auth(this._serviceConfig.user, this._serviceConfig.password)
93+
.send({
94+
text: options.comment
95+
});
96+
}
97+
};
98+
99+
module.exports = StashService;

0 commit comments

Comments
 (0)