jormungandr-bite/src/queue/processors/http/report-github-failure.ts

31 lines
862 B
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import * as request from 'request-promise-native';
import User from '../../../models/user';
const createPost = require('../../../server/api/endpoints/posts/create');
export default async ({ data }, done) => {
try {
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})←←←`;
createPost({ text }, await asyncBot);
} catch (error) {
done(error);
return;
}
done();
};