Skip to content

Commit ef8550b

Browse files
authored
Merge pull request #157 from astoilkov/travis-builds
Travis releases
2 parents 844cd09 + 8d43cb7 commit ef8550b

File tree

7 files changed

+589
-1
lines changed

7 files changed

+589
-1
lines changed

.travis.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
language: node_js
22
node_js:
3-
- "0.10"
3+
- "6.9.4"
44
before_install: npm install -g grunt-cli
55
before_script:
66
- grunt compile
77
- export DISPLAY=:99.0
88
- sh -e /etc/init.d/xvfb start
9+
after_success:
10+
- grunt publish
11+
addons:
12+
apt:
13+
sources:
14+
- ubuntu-toolchain-r-test
15+
packages:
16+
- g++-4.8

build/init.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,6 @@ module.exports = function (grunt) {
102102
grunt.registerTask('compile', ['build', 'combine', 'preprocess', 'debug', 'build-tests-definitions']);
103103
grunt.registerTask('live-compile', ['compile', 'watch:compile']);
104104
grunt.registerTask('full-build', ['jshint', 'compile', 'uglify', 'test', 'npm', 'bower']);
105+
grunt.registerTask('build-only', ['jshint', 'compile', 'uglify', 'npm', 'bower']);
105106
grunt.registerTask('default', []);
106107
};
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
query ($owner: String!, $repo: String!, $afterIssues: String, $afterPRs: String, $includePRs: Boolean!, $includeIssues: Boolean!) {
2+
repository(owner: $owner, name: $repo) {
3+
...issues @include(if: $includeIssues)
4+
...prs @include(if: $includePRs)
5+
parent {
6+
...issues @include(if: $includeIssues)
7+
...prs @include(if: $includePRs)
8+
}
9+
}
10+
}
11+
12+
fragment issues on Repository {
13+
issues(first: 100, after: $afterIssues, states: [CLOSED]) {
14+
pageInfo {
15+
hasNextPage
16+
endCursor
17+
}
18+
nodes {
19+
number
20+
url
21+
title
22+
timeline(first: 100) {
23+
nodes {
24+
... on ReferencedEvent {
25+
commit {
26+
oid
27+
}
28+
}
29+
... on ClosedEvent {
30+
closeCommit: commit {
31+
oid
32+
}
33+
}
34+
}
35+
}
36+
}
37+
}
38+
}
39+
40+
fragment prs on Repository {
41+
pullRequests(first: 100, after: $afterPRs, states: [MERGED]) {
42+
pageInfo {
43+
hasNextPage
44+
endCursor
45+
}
46+
nodes {
47+
title
48+
url
49+
number
50+
timeline(first: 100) {
51+
nodes {
52+
... on MergedEvent {
53+
commit {
54+
oid
55+
}
56+
}
57+
}
58+
}
59+
# unfortunatly seems to be buggy in the alpha of github graphql
60+
# sometime "MERGED" PRs have a mergeCommit and sometimes not
61+
# while they are having a "MergedEvent" timeline
62+
# mergeCommit {
63+
# oid
64+
# }
65+
}
66+
}
67+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
query ($owner: String!, $repo: String!, $after: String, $includeLastRelease: Boolean!) {
2+
repository(owner: $owner, name: $repo) {
3+
...commits
4+
...lastRelease @include(if:$includeLastRelease)
5+
# for some reason releases aren't queryable on forked repos if they weren't published on the fork first
6+
# so include the parent in case the repo doesn't have a last release
7+
parent @include(if: $includeLastRelease) {
8+
...lastRelease
9+
}
10+
}
11+
}
12+
13+
fragment commits on Repository {
14+
ref(qualifiedName: "refs/heads/master") {
15+
target {
16+
... on Commit {
17+
history(first: 100, after: $after) {
18+
pageInfo {
19+
hasNextPage
20+
endCursor
21+
}
22+
nodes {
23+
url
24+
messageHeadline
25+
oid
26+
}
27+
}
28+
}
29+
}
30+
}
31+
}
32+
33+
fragment lastRelease on Repository {
34+
releases(last: 1) {
35+
nodes {
36+
description
37+
tag {
38+
name
39+
target {
40+
oid
41+
}
42+
}
43+
}
44+
}
45+
}

build/publish/github-graphql.js

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
var fetch = require('node-fetch');
2+
var fs = require('fs');
3+
var path = require('path');
4+
5+
var files = {};
6+
7+
function readFileForMethod(method) {
8+
return new Promise(function (resolve, reject) {
9+
if (files[method]) {
10+
return setTimeout(resolve.bind(null, files[method]));
11+
}
12+
fs.readFile(path.resolve(__dirname, method + '.graphql'), function (err, file) {
13+
if (err) {
14+
return reject(err);
15+
}
16+
files[method] = file.toString().replace('\n', '');
17+
resolve(files[method]);
18+
});
19+
});
20+
}
21+
22+
function queryGraphQL (method, vars, key) {
23+
return readFileForMethod(method).then(function (query) {
24+
var body = JSON.stringify({query: query, variables: vars});
25+
return fetch('https://api.github.com/graphql', {
26+
method: 'POST',
27+
headers: {
28+
Authorization: 'bearer ' + key
29+
},
30+
body: body
31+
}).then(res => res.json()).then(function (result) {
32+
if (result.errors && result.errors.length > 0) {
33+
result.errors.forEach(console.error);
34+
throw new Error(result.error[0]);
35+
}
36+
return result;
37+
});
38+
});
39+
}
40+
41+
function hasProperties(obj) {
42+
for (var key in obj) {
43+
return true;
44+
}
45+
return false;
46+
}
47+
48+
function GithubGraphQLWrapper (key, owner, repo) {
49+
this._key = key;
50+
this._repo = repo;
51+
this._owner = owner;
52+
this._commits = [];
53+
this._issues = [];
54+
this._mergedPRs = [];
55+
this._closedIssues = [];
56+
this._lastRelease = null;
57+
this._commitAfterRef = null;
58+
this._reachedLastIssue = false;
59+
this._reachedLastPr = false;
60+
this._afterPRRef = null;
61+
this._afterIssueRef = null;
62+
}
63+
64+
GithubGraphQLWrapper.prototype = {
65+
constructor: GithubGraphQLWrapper,
66+
fetchLastGithubRelease: function fetchLastGithubRelease () {
67+
return queryGraphQL('GetMasterCommits', {
68+
repo: this._repo,
69+
owner: this._owner,
70+
includeLastRelease: true,
71+
after: this._commitAfterRef
72+
}, this._key).then(result => {
73+
var data = result.data.repository;
74+
var parentRelease = data.parent && data.parent.releases.nodes.length && data.parent.releases.nodes[0];
75+
var lastRelease = data.releases.nodes.length > 0 ? data.releases.nodes[0] : parentRelease;
76+
var history = data.ref.target.history;
77+
this._lastRelease = lastRelease;
78+
this._commits = this._commits.concat(history.nodes);
79+
this._commitAfterRef = history.pageInfo.endCursor;
80+
return this;
81+
});
82+
},
83+
fetchCommitsToLastRelease: function () {
84+
return queryGraphQL('GetMasterCommits', {
85+
repo: this._repo,
86+
owner: this._owner,
87+
includeLastRelease: false,
88+
after: this._commitAfterRef
89+
}, this._key).then(result => {
90+
var data = result.data.repository;
91+
var history = data.ref.target.history;
92+
this._commitAfterRef = data.ref.target.history.pageInfo.endCursor;
93+
this._commits = this._commits.concat(data.ref.target.history.nodes);
94+
var commitOids = this._commits.map(c => c.oid);
95+
if (commitOids.indexOf(this._lastRelease.tag.target.oid) == -1 && history.pageInfo.hasNextPage) {
96+
return this.fetchCommitsToLastRelease();
97+
}
98+
this._commits.splice(commitOids.indexOf(this._lastRelease.tag.target.oid));
99+
return this;
100+
});
101+
},
102+
fetchPRsAndIssues: function () {
103+
return queryGraphQL('GetClosedIssuesAndMergedPRs', {
104+
repo: this._repo,
105+
owner: this._owner,
106+
includePRs: !this._reachedLastPr,
107+
includeIssues: !this._reachedLastIssue,
108+
afterIssues: this._afterIssueRef,
109+
afterPRs: this._afterPRRef,
110+
}, this._key).then(result => {
111+
var repository = result.data.repository;
112+
var parent = repository.parent;
113+
var parentIssues = parent && parent.issues && parent.issues.nodes.length && parent.issues;
114+
var localIssues = repository.issues && repository.issues.nodes.length && repository.issues;
115+
var issues = localIssues || parentIssues;
116+
var parentPRs = parent && parent.pullRequests && parent.pullRequests.nodes.length && parent.pullRequests;
117+
var localPRs = repository.pullRequests && repository.pullRequests.nodes.length && repository.pullRequests;
118+
var prs = localPRs || parentPRs;
119+
if (issues) {
120+
this._reachedLastIssue = !issues.pageInfo.hasNextPage;
121+
this._afterIssueRef = issues.pageInfo.endCursor;
122+
this._closedIssues = this._closedIssues.concat(issues.nodes);
123+
}
124+
125+
if (prs) {
126+
this._reachedLastPr = !prs.pageInfo.hasNextPage;
127+
this._afterPRRef = prs.pageInfo.endCursor;
128+
this._mergedPRs = this._mergedPRs.concat(prs.nodes);
129+
}
130+
if (!this._reachedLastPr && !this._reachedLastIssue) {
131+
return this.fetchPRsAndIssues();
132+
}
133+
}).then(() => {
134+
this._closedIssues = this._closedIssues.map(issue => {
135+
issue.timeline = issue.timeline.nodes.filter(hasProperties);
136+
return issue;
137+
}).filter(issue => issue.timeline.length > 0);
138+
this._mergedPRs.map(pr => {
139+
pr.timeline = pr.timeline.nodes.filter(hasProperties);
140+
return pr;
141+
}).filter(pr => pr.timeline.length > 0);
142+
return this;
143+
});
144+
},
145+
getLastRelease: function () {
146+
return this._lastRelease;
147+
},
148+
getMergedPRs: function () {
149+
return this._mergedPRs;
150+
},
151+
getCommits: function () {
152+
return this._commits;
153+
},
154+
getClosedIssues: function () {
155+
return this._closedIssues;
156+
},
157+
getOwner: function () {
158+
return this._owner;
159+
},
160+
getRepo: function () {
161+
return this._repo;
162+
}
163+
};
164+
165+
module.exports = GithubGraphQLWrapper;

0 commit comments

Comments
 (0)