1
+ const http = require ( 'https' ) ;
2
+ const fs = require ( 'fs' ) ;
3
+
4
+ const options = {
5
+ host : 'api.github.com' ,
6
+ path : '/repos/lastnpe/eclipse-null-eea-augments/pulls?page=1&per_page=100&state=closed' ,
7
+ headers : { 'User-Agent' : 'LastNPE / 1.0.0' }
8
+ } ;
9
+
10
+ const releaseTag = process . argv [ 2 ] ;
11
+
12
+ if ( releaseTag == null || ! releaseTag . match ( / \d + \. \d + \. \d + / ) ) {
13
+ console . error ( "Please provide release tag as argument in x.y.z format." ) ;
14
+ return ;
15
+ }
16
+
17
+ const request = http . request ( options , function ( res ) {
18
+ let rawData = '' ;
19
+ res . on ( 'data' , function ( chunk ) {
20
+ rawData += chunk ;
21
+ } ) ;
22
+ res . on ( 'end' , function ( ) {
23
+ try {
24
+ let fullJson = JSON . parse ( rawData ) ;
25
+ let releasePr = [ ] ;
26
+ fullJson . forEach ( pr => {
27
+ if ( pr . merged_at != null && pr . milestone != null && pr . milestone . title === releaseTag ) {
28
+ let module = pr . title . match ( / \[ ( .* ) \] / ) [ 1 ] ;
29
+ if ( module !== 'infrastructure' ) {
30
+ releasePr . push ( {
31
+ 'module' : module ,
32
+ 'label' : pr . labels . map ( label => label . name ) ,
33
+ 'title' : pr . title . match ( / \[ .* \] \s ( .* ) / ) [ 1 ] ,
34
+ 'issue' : parseInt ( pr . url . match ( / \/ ( \d + ) $ / ) [ 1 ] ) ,
35
+ 'url' : pr . url
36
+ } ) ;
37
+ }
38
+ }
39
+ } ) ;
40
+ releasePr . sort ( function ( a , b ) {
41
+ // sort-order: module, issue
42
+ if ( a . module === b . module ) {
43
+ return a . issue < b . issue ? - 1 : 1 ;
44
+ } else {
45
+ return a . module < b . module ? - 1 : 1 ;
46
+ }
47
+ } ) ;
48
+
49
+ // output the table
50
+ let output = '# Eclipse Null EEA Augments Release ' + releaseTag + '\n\n' ;
51
+ output += 'This is the latest release of the external null annotations for the Eclipse null checker.\n' ;
52
+ output += 'Please see below for a list of all changes since the last release.\n\n' ;
53
+ output += '## Changelog\n\n' ;
54
+ output += '| Module | Type | Issue | Description |\n'
55
+ output += '|---|---|:---:|---|\n' ;
56
+
57
+ let lastModule = ''
58
+ releasePr . forEach ( pr => {
59
+ output += '|' + ( lastModule !== pr . module ? pr . module : ' ' ) + '|' ;
60
+ pr . label . forEach ( label => output += label + " " ) ;
61
+ output += '|[#' + pr . issue + '](' + pr . url + ')|' + pr . title + '|\n' ;
62
+ lastModule = pr . module ;
63
+ } ) ;
64
+
65
+ // check if target directory exists (using target prevents locally generated release notes from being checked in)
66
+ if ( ! fs . existsSync ( 'target' ) ) {
67
+ fs . mkdir ( 'target' , ( err ) => {
68
+ if ( err ) {
69
+ console . error ( err )
70
+ }
71
+ } ) ;
72
+ }
73
+
74
+ fs . writeFile ( 'target/releaseNotes-' + releaseTag + '.md' , output , ( err ) => {
75
+ if ( err ) {
76
+ console . error ( err ) ;
77
+ }
78
+ } ) ;
79
+ } catch ( error ) {
80
+ console . error ( error . message ) ;
81
+ }
82
+ } ) ;
83
+ } ) ;
84
+
85
+ request . on ( 'error' , function ( e ) {
86
+ console . error ( e . message ) ;
87
+ } ) ;
88
+
89
+ request . end ( ) ;
0 commit comments