summaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-04-09 17:38:22 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-04-09 17:38:22 +0900
commit2a5016865ad0ed98ab8da3364b5f006bf26f45c5 (patch)
tree37732ac4a68248e62aa957a91550585dc91e532e /src/server
parentFix bug (diff)
downloadsharkey-2a5016865ad0ed98ab8da3364b5f006bf26f45c5.tar.gz
sharkey-2a5016865ad0ed98ab8da3364b5f006bf26f45c5.tar.bz2
sharkey-2a5016865ad0ed98ab8da3364b5f006bf26f45c5.zip
Fix bug
Diffstat (limited to 'src/server')
-rw-r--r--src/server/api/service/github.ts46
1 files changed, 30 insertions, 16 deletions
diff --git a/src/server/api/service/github.ts b/src/server/api/service/github.ts
index 6a327f1f76..6b1d5d25be 100644
--- a/src/server/api/service/github.ts
+++ b/src/server/api/service/github.ts
@@ -1,16 +1,17 @@
import * as EventEmitter from 'events';
import * as express from 'express';
-//const crypto = require('crypto');
+import * as request from 'request';
+const crypto = require('crypto');
+
import User from '../../../models/user';
+import createNote from '../../../services/note/create';
import config from '../../../config';
-import { createHttp } from '../../../queue';
module.exports = async (app: express.Application) => {
if (config.github_bot == null) return;
const bot = await User.findOne({
- usernameLower: config.github_bot.username.toLowerCase(),
- host: null
+ username_lower: config.github_bot.username.toLowerCase()
});
if (bot == null) {
@@ -18,7 +19,7 @@ module.exports = async (app: express.Application) => {
return;
}
- const post = text => require('../endpoints/notes/create')({ text }, bot);
+ const post = text => createNote(bot, { text });
const handler = new EventEmitter();
@@ -26,12 +27,12 @@ module.exports = async (app: express.Application) => {
// req.headers['x-hub-signature'] および
// req.headers['x-github-event'] は常に string ですが、型定義の都合上
// string | string[] になっているので string を明示しています
-// if ((new Buffer(req.headers['x-hub-signature'] as string)).equals(new Buffer(`sha1=${crypto.createHmac('sha1', config.github_bot.hook_secret).update(JSON.stringify(req.body)).digest('hex')}`))) {
+ if ((new Buffer(req.headers['x-hub-signature'] as string)).equals(new Buffer(`sha1=${crypto.createHmac('sha1', config.github_bot.hook_secret).update(JSON.stringify(req.body)).digest('hex')}`))) {
handler.emit(req.headers['x-github-event'] as string, req.body);
res.sendStatus(200);
-// } else {
-// res.sendStatus(400);
-// }
+ } else {
+ res.sendStatus(400);
+ }
});
handler.on('status', event => {
@@ -42,13 +43,26 @@ module.exports = async (app: express.Application) => {
const commit = event.commit;
const parent = commit.parents[0];
- createHttp({
- type: 'gitHubFailureReport',
- userId: bot._id,
- parentUrl: parent.url,
- htmlUrl: commit.html_url,
- message: commit.commit.message,
- }).save();
+ // Fetch parent status
+ request({
+ url: `${parent.url}/statuses`,
+ headers: {
+ 'User-Agent': 'misskey'
+ }
+ }, (err, res, body) => {
+ if (err) {
+ console.error(err);
+ return;
+ }
+ const parentStatuses = JSON.parse(body);
+ const parentState = parentStatuses[0].state;
+ const stillFailed = parentState == 'failure' || parentState == 'error';
+ if (stillFailed) {
+ post(`**⚠️BUILD STILL FAILED⚠️**: ?[${commit.commit.message}](${commit.html_url})`);
+ } else {
+ post(`**🚨BUILD FAILED🚨**: →→→?[${commit.commit.message}](${commit.html_url})←←←`);
+ }
+ });
break;
}
});