-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
171 lines (131 loc) · 5.62 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/**
* Post Commit Autotag
*
* This project is meant to be a Post Recieve Callback URL
* for automatically re-opening github issues that were closed
* via the comment message (i.e. "Fixes #142 where there was a typo")
*
* Author: Charles Himmer
*/
/**
* Load Dependecy Modules
*/
var Express = require('express'),
GitHubUtilies = require('./github/utilities');
GitHubIssuesApi = require("./github/api/Issues");
/**
* App Configruation
*/
// setup express server
var App = Express.createServer();
// allow for post body parsing
App.use(Express.bodyParser());
// Initial GitHubIssuesAPI settings
var config = {
apiKey:'e45866771748f7df1021ecc0236b83ec', // insert working api key, this is a dummy one
user:'charleshimmer',
repo:'post-commit-autotag'
};
GitHubIssuesApi.initialize(config);
// setup port for server to listen on
App.listen(80);
/**
* URL Routing
*/
/**
* Define post request at /post-commit-autotag
*/
App.post('/post-commit-autotag',function(req, res){
// get post data
var post = JSON.parse(req.body.payload);
// security check to make sure we are only working with our repository
if(post.repository.name != config.repo){
return;
}
// get which issues where closed
var issues = GitHubUtilies.getClosedIssues(post.commits);
// apply labels
GitHubIssuesApi.applyLabels(issues, 'Testable');
// reopen those issues
GitHubIssuesApi.reopen(issues);
});// end of post('/post-commit-autotag');
/**
* Run testing suite for API calls
*
*/
App.get('/testAPI', function(req, res){
// setup fake issue ids
var issues = ['2','3','5'];
// test my API calls
GitHubIssuesApi.reopen(issues);
GitHubIssuesApi.applyLabels(issues, 'Testable');
// return to the browser with something
res.end('<title>Post Commit Autotag</title>API call testing suite has been ran.');
});// end of get('/testAPI');
/**
* Run testing suite for getting Closed Issues
*
*/
App.get('/testMessage', function(req, res){
var assert = require('assert');
// test data
var commits = [{
timestamp: '2011-03-26T01:17:16-07:00',
distinct: true,
url: 'https://github.com/charleshimmer/post-commit-autotag/commit/9049052c4c3f9f8c2ea548c78ecc5344aae24483',
message: 'Closes #5 testing',
id: '9049052c4c3f9f8c2ea548c78ecc5344aae24483'
}];
console.log(GitHubUtilies.getClosedIssues(commits));
var commits = [{
timestamp: '2011-03-26T01:17:16-07:00',
distinct: true,
url: 'https://github.com/charleshimmer/post-commit-autotag/commit/9049052c4c3f9f8c2ea548c78ecc5344aae24483',
message: 'Updated README.md and to test multiple fixes, Fixes #4 Fixes #6',
id: '9049052c4c3f9f8c2ea548c78ecc5344aae24483'
},{
timestamp: '2011-03-26T01:17:16-07:00',
distinct: true,
url: 'https://github.com/charleshimmer/post-commit-autotag/commit/9049052c4c3f9f8c2ea548c78ecc5344aae24483',
message: '=Fixes #42, closes #2 this is some dummy test Closes #2',
id: '9049052c4c3f9f8c2ea548c78ecc5344aae24483'
}];
console.log(GitHubUtilies.getClosedIssues(commits));
var commits = [{
timestamp: '2011-03-26T01:17:16-07:00',
distinct: true,
url: 'https://github.com/charleshimmer/post-commit-autotag/commit/9049052c4c3f9f8c2ea548c78ecc5344aae24483',
message: 'Updated README.md and to test multiple fixes, Fixes #53 Fixes #15',
id: '9049052c4c3f9f8c2ea548c78ecc5344aae24483'
},{
timestamp: '2011-03-26T01:17:16-07:00',
distinct: true,
url: 'https://github.com/charleshimmer/post-commit-autotag/commit/9049052c4c3f9f8c2ea548c78ecc5344aae24483',
message: '=Fixes #2, closes #53 this is some dummy test Closes #23',
id: '9049052c4c3f9f8c2ea548c78ecc5344aae24483'
},{
timestamp: '2011-03-26T01:17:16-07:00',
distinct: true,
url: 'https://github.com/charleshimmer/post-commit-autotag/commit/9049052c4c3f9f8c2ea548c78ecc5344aae24483',
message: '=Fixes #7, closes #563 this is some dummy test Closes #273',
id: '9049052c4c3f9f8c2ea548c78ecc5344aae24483'
},{
timestamp: '2011-03-26T01:17:16-07:00',
distinct: true,
url: 'https://github.com/charleshimmer/post-commit-autotag/commit/9049052c4c3f9f8c2ea548c78ecc5344aae24483',
message: '=Fixes #23, closes #78 this is some dummy test Closes #84',
id: '9049052c4c3f9f8c2ea548c78ecc5344aae24483'
}];
console.log(GitHubUtilies.getClosedIssues(commits));
// return to the browser with something
res.end('<title>Post Commit Autotag</title>Capture closed issue testing suite has been ran.');
});// end of get('/testAPI');
/**
* Define basic get request to server, more for checking that
* the server is up.
*/
App.get('/', function(req, res){
// basic url hit
res.end('<title>Post Commit Autotag</title>Server is waiting for requests...');
});// end of get('/');
// end of app.js