mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-27 09:03:08 +02:00
Fix bug
This commit is contained in:
parent
64547965b4
commit
2a5016865a
3 changed files with 30 additions and 42 deletions
|
@ -1,11 +1,9 @@
|
||||||
import deliver from './deliver';
|
import deliver from './deliver';
|
||||||
import processInbox from './process-inbox';
|
import processInbox from './process-inbox';
|
||||||
import reportGitHubFailure from './report-github-failure';
|
|
||||||
|
|
||||||
const handlers = {
|
const handlers = {
|
||||||
deliver,
|
deliver,
|
||||||
processInbox,
|
processInbox,
|
||||||
reportGitHubFailure
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (job, done) => {
|
export default (job, done) => {
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
import * as request from 'request-promise-native';
|
|
||||||
import User from '../../../models/user';
|
|
||||||
import createNote from '../../../services/note/create';
|
|
||||||
|
|
||||||
export default async ({ data }) => {
|
|
||||||
const asyncBot = User.findOne({ _id: data.userId });
|
|
||||||
|
|
||||||
// Fetch parent status
|
|
||||||
const parentStatuses = await request({
|
|
||||||
url: `${data.parentUrl}/statuses`,
|
|
||||||
headers: {
|
|
||||||
'User-Agent': 'misskey'
|
|
||||||
},
|
|
||||||
json: true
|
|
||||||
});
|
|
||||||
|
|
||||||
const parentState = parentStatuses[0].state;
|
|
||||||
const stillFailed = parentState == 'failure' || parentState == 'error';
|
|
||||||
const text = stillFailed ?
|
|
||||||
`**⚠️BUILD STILL FAILED⚠️**: ?[${data.message}](${data.htmlUrl})` :
|
|
||||||
`**🚨BUILD FAILED🚨**: →→→?[${data.message}](${data.htmlUrl})←←←`;
|
|
||||||
|
|
||||||
createNote(await asyncBot, { text });
|
|
||||||
};
|
|
|
@ -1,16 +1,17 @@
|
||||||
import * as EventEmitter from 'events';
|
import * as EventEmitter from 'events';
|
||||||
import * as express from 'express';
|
import * as express from 'express';
|
||||||
//const crypto = require('crypto');
|
import * as request from 'request';
|
||||||
|
const crypto = require('crypto');
|
||||||
|
|
||||||
import User from '../../../models/user';
|
import User from '../../../models/user';
|
||||||
|
import createNote from '../../../services/note/create';
|
||||||
import config from '../../../config';
|
import config from '../../../config';
|
||||||
import { createHttp } from '../../../queue';
|
|
||||||
|
|
||||||
module.exports = async (app: express.Application) => {
|
module.exports = async (app: express.Application) => {
|
||||||
if (config.github_bot == null) return;
|
if (config.github_bot == null) return;
|
||||||
|
|
||||||
const bot = await User.findOne({
|
const bot = await User.findOne({
|
||||||
usernameLower: config.github_bot.username.toLowerCase(),
|
username_lower: config.github_bot.username.toLowerCase()
|
||||||
host: null
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (bot == null) {
|
if (bot == null) {
|
||||||
|
@ -18,7 +19,7 @@ module.exports = async (app: express.Application) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const post = text => require('../endpoints/notes/create')({ text }, bot);
|
const post = text => createNote(bot, { text });
|
||||||
|
|
||||||
const handler = new EventEmitter();
|
const handler = new EventEmitter();
|
||||||
|
|
||||||
|
@ -26,12 +27,12 @@ module.exports = async (app: express.Application) => {
|
||||||
// req.headers['x-hub-signature'] および
|
// req.headers['x-hub-signature'] および
|
||||||
// req.headers['x-github-event'] は常に string ですが、型定義の都合上
|
// req.headers['x-github-event'] は常に string ですが、型定義の都合上
|
||||||
// string | string[] になっているので 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);
|
handler.emit(req.headers['x-github-event'] as string, req.body);
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
// } else {
|
} else {
|
||||||
// res.sendStatus(400);
|
res.sendStatus(400);
|
||||||
// }
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on('status', event => {
|
handler.on('status', event => {
|
||||||
|
@ -42,13 +43,26 @@ module.exports = async (app: express.Application) => {
|
||||||
const commit = event.commit;
|
const commit = event.commit;
|
||||||
const parent = commit.parents[0];
|
const parent = commit.parents[0];
|
||||||
|
|
||||||
createHttp({
|
// Fetch parent status
|
||||||
type: 'gitHubFailureReport',
|
request({
|
||||||
userId: bot._id,
|
url: `${parent.url}/statuses`,
|
||||||
parentUrl: parent.url,
|
headers: {
|
||||||
htmlUrl: commit.html_url,
|
'User-Agent': 'misskey'
|
||||||
message: commit.commit.message,
|
}
|
||||||
}).save();
|
}, (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;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue