Skip to content

Commit 1a4721b

Browse files
committed
GitHub: Implemented changelog generation
Fixes gh-1 Closes gh-8
1 parent e2a97ba commit 1a4721b

File tree

9 files changed

+404
-61
lines changed

9 files changed

+404
-61
lines changed

lib/changelog.js

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ module.exports = function( Release ) {
77
Release.define({
88
_generateChangelog: function( callback ) {
99
Release._generateCommitChangelog(function( commitChangelog ) {
10-
var changelogPath = Release.dir.base + "/changelog",
11-
changelog = Release.changelogShell() +
12-
commitChangelog +
13-
Release._generateIssueChangelog();
14-
15-
fs.writeFileSync( changelogPath, changelog );
16-
console.log( "Stored changelog in " + chalk.cyan( changelogPath ) + "." );
17-
callback();
10+
Release._generateIssueChangelog(function( issueChangelog ) {
11+
var changelogPath = Release.dir.base + "/changelog",
12+
changelog = Release.changelogShell() +
13+
commitChangelog +
14+
"\n\n\n" +
15+
"--- Issue List ---\n" +
16+
issueChangelog;
17+
18+
fs.writeFileSync( changelogPath, changelog );
19+
console.log( "Stored changelog in " + chalk.cyan( changelogPath ) + "." );
20+
21+
callback();
22+
});
1823
});
1924
},
2025

@@ -43,21 +48,10 @@ Release.define({
4348
});
4449
},
4550

46-
_generateIssueChangelog: function() {
51+
_generateIssueChangelog: function( callback ) {
4752
return Release.issueTracker === "trac" ?
48-
Release._generateTracChangelog() :
49-
Release._generateGithubChangelog();
50-
},
51-
52-
_generateTracChangelog: function() {
53-
console.log( "Adding Trac tickets..." );
54-
return Release.trac( "/query?milestone=" + Release.tracMilestone() + "&resolution=fixed" +
55-
"&col=id&col=component&col=summary&order=component" ) + "\n";
56-
},
57-
58-
_generateGithubChangelog: function() {
59-
console.log( "Adding GitHub issues..." );
60-
// TODO
53+
Release._generateTracChangelog( callback ) :
54+
Release._generateGithubChangelog( callback );
6155
}
6256
});
6357

lib/contributors.js

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,37 @@ function unique( arr ) {
1212
}
1313

1414
Release.define({
15-
_gatherContributors: function() {
16-
var contributors,
17-
contributorsPath = Release.dir.base + "/contributors.txt";
18-
19-
console.log( "Adding committers and authors..." );
20-
Release.chdir( Release.dir.repo );
21-
contributors = Release.gitLog( "%aN%n%cN" );
15+
_gatherContributors: function( callback ) {
16+
var contributorsPath = Release.dir.base + "/contributors.txt";
2217

2318
console.log( "Adding reporters and commenters from issues..." );
24-
contributors = contributors.concat( Release._gatherIssueContributors() );
25-
26-
console.log( "Sorting contributors..." );
27-
contributors = unique( contributors ).sort(function( a, b ) {
28-
return a.toLowerCase() < b.toLowerCase() ? -1 : 1;
19+
Release._gatherIssueContributors(function( contributors ) {
20+
console.log( "Adding committers and authors..." );
21+
Release.chdir( Release.dir.repo );
22+
contributors = contributors.concat( Release.gitLog( "%aN%n%cN" ) );
23+
24+
console.log( "Sorting contributors..." );
25+
contributors = unique( contributors ).sort(function( a, b ) {
26+
return a.toLowerCase() < b.toLowerCase() ? -1 : 1;
27+
});
28+
29+
console.log( "Adding people thanked in commits..." );
30+
contributors = contributors.concat(
31+
Release.gitLog( "%b%n%s" ).filter(function( line ) {
32+
return (/thank/i).test( line );
33+
}));
34+
35+
fs.writeFileSync( contributorsPath, contributors.join( "\n" ) );
36+
console.log( "Stored contributors in " + chalk.cyan( contributorsPath ) + "." );
37+
38+
callback();
2939
});
30-
31-
console.log( "Adding people thanked in commits..." );
32-
contributors = contributors.concat(
33-
Release.gitLog( "%b%n%s" ).filter(function( line ) {
34-
return (/thank/i).test( line );
35-
}));
36-
37-
fs.writeFileSync( contributorsPath, contributors.join( "\n" ) );
38-
console.log( "Stored contributors in " + chalk.cyan( contributorsPath ) + "." );
3940
},
4041

41-
_gatherIssueContributors: function() {
42+
_gatherIssueContributors: function( callback ) {
4243
return Release.issueTracker === "trac" ?
43-
Release._gatherTracContributors() :
44-
Release._gatherGithubIssueContributors();
45-
},
46-
47-
_gatherTracContributors: function() {
48-
var url = "/report/" + Release.contributorReportId +
49-
"?V=" + Release.tracMilestone() + "&max=-1";
50-
51-
return Release.trac( url )
52-
.split( /\r?\n/ )
53-
54-
// Remove header and trailing newline
55-
.slice( 1, -1 );
56-
},
57-
58-
_gatherGithubIssueContributors: function() {
59-
// TODO
44+
Release._gatherTracContributors( callback ) :
45+
Release._gatherGithubIssueContributors( callback );
6046
}
6147
});
6248

lib/github.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
var querystring = require( "querystring" );
2+
var github = require( "github-request" );
3+
4+
module.exports = function( Release ) {
5+
6+
Release.define({
7+
_githubApiPath: function( path ) {
8+
var repoUrl = Release._packageUrl( "bugs" );
9+
var repo = repoUrl.match( /github\.com\/(\w+\/\w+)/ )[ 1 ];
10+
return "/repos/" + repo + "/" + path;
11+
},
12+
13+
_githubMilestone: function( callback ) {
14+
github.requestAll({
15+
path: Release._githubApiPath( "milestones" )
16+
}, function( error, milestones ) {
17+
if ( error ) {
18+
Release.abort( "Error getting milestones.", error );
19+
}
20+
21+
var milestone = milestones.filter(function( milestone ) {
22+
return milestone.title === Release.newVersion;
23+
})[ 0 ];
24+
25+
if ( !milestone ) {
26+
Release.abort( "No milestone found." );
27+
}
28+
29+
callback( milestone.number );
30+
});
31+
},
32+
33+
_generateGithubChangelog: function( callback ) {
34+
Release._githubMilestone(function( milestone ) {
35+
github.requestAll({
36+
path: Release._githubApiPath( "issues?" + querystring.stringify( {
37+
milestone: milestone,
38+
state: "closed"
39+
} ) ),
40+
}, function( error, issues ) {
41+
if ( error ) {
42+
return Release.abort( "Error getting issues.", error );
43+
}
44+
45+
var changelog = issues
46+
47+
// Remove pull requests from results
48+
.filter(function( issue ) {
49+
return !issue.pull_request;
50+
})
51+
52+
// Convert each issue to text
53+
.map(function( issue ) {
54+
var component = "(none)";
55+
56+
issue.labels.forEach(function( label ) {
57+
if ( /^component:/i.test( label.name ) ) {
58+
component = label.name.substring( 11 );
59+
}
60+
});
61+
62+
return [
63+
"#" + issue.number,
64+
component,
65+
issue.title
66+
]
67+
.sort(function( a, b ) {
68+
return a.component > b.component ? 1 : -1;
69+
})
70+
.join( "\t" );
71+
})
72+
73+
// Concatenate the issues into a string
74+
.join( "\n" ) + "\n";
75+
76+
callback( changelog );
77+
});
78+
});
79+
},
80+
81+
_gatherGithubIssueContributors: function( callback ) {
82+
83+
// TODO
84+
process.nextTick(function() {
85+
callback( [] );
86+
});
87+
}
88+
});
89+
90+
};

lib/trac.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,30 @@ Release.define({
77
command: "curl -s '" + tracUrl + path + "&format=tab'",
88
silent: true
99
}, "Error getting Trac data." );
10+
},
11+
12+
_generateTracChangelog: function( callback ) {
13+
process.nextTick(function() {
14+
console.log( "Adding Trac tickets..." );
15+
var changelog = Release.trac(
16+
"/query?milestone=" + Release.newVersion + "&resolution=fixed" +
17+
"&col=id&col=component&col=summary&order=component" ) + "\n";
18+
callback( changelog );
19+
});
20+
},
21+
22+
_gatherTracContributors: function( callback ) {
23+
var url = "/report/" + Release.contributorReportId +
24+
"?V=" + Release.tracMilestone() + "&max=-1";
25+
26+
process.nextTick(function() {
27+
callback( Release.trac( url )
28+
.split( /\r?\n/ )
29+
30+
// Remove header and trailing newline
31+
.slice( 1, -1 )
32+
);
33+
});
1034
}
1135
});
1236

node_modules/github-request/LICENSE.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: 69 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)