Skip to content

Commit ea69962

Browse files
committed
GitHub: Implemented changelog generation
Fixes gh-1
1 parent b3ec7b9 commit ea69962

File tree

8 files changed

+315
-23
lines changed

8 files changed

+315
-23
lines changed

lib/changelog.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@ var fs = require( "fs" );
33
module.exports = function( Release ) {
44

55
Release.define({
6-
_generateChangelog: function() {
7-
var changelogPath = Release.dir.base + "/changelog",
8-
changelog = Release.changelogShell() +
9-
Release._generateCommitChangelog() +
10-
Release._generateIssueChangelog();
11-
12-
fs.writeFileSync( changelogPath, changelog );
13-
console.log( "Stored changelog in " + changelogPath.cyan + "." );
6+
_generateChangelog: function( callback ) {
7+
Release._generateIssueChangelog(function( error, issueChangelog ) {
8+
if ( error ) {
9+
return callback( error );
10+
}
11+
12+
var changelogPath = Release.dir.base + "/changelog",
13+
changelog = Release.changelogShell() +
14+
Release._generateCommitChangelog() +
15+
issueChangelog;
16+
17+
fs.writeFileSync( changelogPath, changelog );
18+
console.log( "Stored changelog in " + changelogPath.cyan + "." );
19+
20+
callback( null );
21+
});
1422
},
1523

1624
changelogShell: function() {
@@ -53,21 +61,10 @@ Release.define({
5361
.join( "\n" ) + "\n";
5462
},
5563

56-
_generateIssueChangelog: function() {
64+
_generateIssueChangelog: function( callback ) {
5765
return Release.issueTracker === "trac" ?
58-
Release._generateTracChangelog() :
59-
Release._generateGithubChangelog();
60-
},
61-
62-
_generateTracChangelog: function() {
63-
console.log( "Adding Trac tickets..." );
64-
return Release.trac( "/query?milestone=" + Release.newVersion + "&resolution=fixed" +
65-
"&col=id&col=component&col=summary&order=component" ) + "\n";
66-
},
67-
68-
_generateGithubChangelog: function() {
69-
console.log( "Adding GitHub issues..." );
70-
// TODO
66+
Release._generateTracChangelog( callback ) :
67+
Release._generateGithubChangelog( callback );
7168
}
7269
});
7370

lib/github.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
var url = require( "url" ),
2+
github = require( "github" );
3+
4+
module.exports = function( Release ) {
5+
6+
Release.define({
7+
_githubRequest: function( settings, data, callback ) {
8+
if ( typeof data === "function" ) {
9+
callback = data;
10+
data = null;
11+
}
12+
13+
github.request( settings, data, function( error, first, meta ) {
14+
if ( error ) {
15+
return callback( error );
16+
}
17+
18+
if ( !meta.links || !meta.links.next ) {
19+
return callback( null, first );
20+
}
21+
22+
settings.path = url.parse( meta.links.next ).path;
23+
Release._githubRequest( settings, data, function( error, next ) {
24+
if ( error ) {
25+
return callback( error );
26+
}
27+
28+
callback( null, first.concat( next ) );
29+
});
30+
});
31+
},
32+
33+
_githubMilestone: function( callback ) {
34+
Release._githubRequest({
35+
path: "/repos/jquery/" + Release.project + "/milestones"
36+
}, function( error, milestones ) {
37+
if ( error ) {
38+
return callback( error );
39+
}
40+
41+
var milestone = milestones.filter(function( milestone ) {
42+
return milestone.title === Release.newVersion;
43+
})[ 0 ];
44+
45+
if ( !milestone ) {
46+
return callback( new Error( "No milestone found." ) );
47+
}
48+
49+
callback( null, milestone.number );
50+
});
51+
},
52+
53+
_generateGithubChangelog: function( callback ) {
54+
Release._githubMilestone(function( error, milestone ) {
55+
if ( error ) {
56+
return callback( error );
57+
}
58+
59+
Release._githubRequest({
60+
path: "/repos/jquery/" + Release.project + "/issues",
61+
}, {
62+
milestone: milestone,
63+
status: "closed"
64+
}, function( error, issues ) {
65+
if ( error ) {
66+
return callback( error );
67+
}
68+
69+
var changelog = issues.map(function( issue ) {
70+
var component = "(none)";
71+
72+
issues.labels.forEach(function( label ) {
73+
if ( /^component:/.test( label.name ) ) {
74+
component = label.name.substring( 11 );
75+
}
76+
});
77+
78+
return [
79+
"#" + issue.number,
80+
component,
81+
issue.title
82+
].sort(function( a, b ) {
83+
return a.component > b.component ? 1 : -1;
84+
}).join( "\t" );
85+
}).join( "\n" ) + "\n";
86+
87+
callback( null, changelog );
88+
});
89+
});
90+
}
91+
});
92+
93+
};

lib/trac.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ Release.define({
1010
}
1111

1212
return result.output;
13+
},
14+
15+
_generateTracChangelog: function( callback ) {
16+
process.nextTick(function() {
17+
console.log( "Adding Trac tickets..." );
18+
var changelog = Release.trac(
19+
"/query?milestone=" + Release.newVersion + "&resolution=fixed" +
20+
"&col=id&col=component&col=summary&order=component" ) + "\n";
21+
callback( null, changelog );
22+
});
1323
}
1424
});
1525

node_modules/github-request/LICENSE-MIT.txt

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/github-request/README.md

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/github-request/lib/request.js

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/github-request/package.json

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"dependencies": {
33
"colors": "0.6.2",
4-
"shelljs": "0.2.6"
4+
"shelljs": "0.2.6",
5+
"github-request": "1.1.0"
56
},
67
"devDependencies": {
78
"grunt": "0.4.1",

0 commit comments

Comments
 (0)