1 Commits

Author SHA1 Message Date
ec6edf598c feat: fetch data for prs that need retest 2018-10-17 17:26:27 -07:00
5 changed files with 16 additions and 116 deletions

View File

@@ -16,16 +16,7 @@ export default async function() {
const comments = (await getComments(repo, { const comments = (await getComments(repo, {
body: /build failed/i, body: /build failed/i,
actor: 'elasticmachine', actor: 'elasticmachine',
})).filter(comment => true /*!history.get(comment.id)*/); })).filter(comment => !history.get(comment.id));
console.log(
comments
.map(comment => {
history.add(comment); // temp
return comment.number;
})
.join(',')
);
// read pull data, filter out any closed pulls // read pull data, filter out any closed pulls
const pulls = (await Promise.all( const pulls = (await Promise.all(
@@ -36,37 +27,25 @@ export default async function() {
}) })
)).filter(Boolean); )).filter(Boolean);
const commits = await Promise.all(pulls.map(pull => getCommits(repo, pull.number, true))); const records = (await Promise.all(
pulls.map(async ({ pull, comment }) => {
const commit = await getCommits(repo, pull.number, true);
const buildStatus = await getCommitStatus(repo, commit.sha);
// do nothing if the build has not started, or is pending or successful
if (!buildStatus || buildStatus.state === 'pending' || buildStatus.state === 'success')
return false;
return { comment, pull, commit, buildStatus };
})
)).filter(Boolean);
const buildStatus = await getCommitStatus(repo, commits[1].sha); console.log(records);
console.log(buildStatus);
process.exit(); process.exit();
Promise.resolve()
.then(commit =>
// get the status of the commit
repo.commits(commit.sha).statuses.fetch()
)
.then(statuses => {
if (statuses.lastPage) return statuses.lastPage.fetch();
return statuses;
})
.then(({ items }) => {
const buildStatus = items.find(item => item.context === 'kibana-ci');
// status will be one of: error, failure, pending, success
// we should skip the retest if the state is pending or success
console.log(`PR state: ${buildStatus.state}`);
return buildStatus;
})
.catch(err => console.error(err));
/* /*
TODO: TODO:
- [ ] keep track of seen comment ids, only process new ones - [x] keep track of seen comment ids, only process new ones
- [x] check the pr's status and only retest if no longer "Pending" - [x] check the pr's status and only retest if no longer "Pending"
- [ ] add a retest comment - [ ] add a retest comment
- POST /repos/:owner/:repo/issues/:number/comments - POST /repos/:owner/:repo/issues/:number/comments

View File

@@ -1,5 +1,4 @@
export default async function getEvents(repo, { body, actor } = {}) { export default async function getEvents(repo, { body, actor } = {}) {
return cache;
const { items: events } = await repo.events.fetch(); const { items: events } = await repo.events.fetch();
return events return events
@@ -22,67 +21,3 @@ export default async function getEvents(repo, { body, actor } = {}) {
}) })
.filter(Boolean); .filter(Boolean);
} }
const cache = [ { id: '8438445273',
number: 23819,
owner: 'mattapperson',
labels: [ ':Beats', 'beats-cm' ],
comment_id: 430790622,
comment_author: 'elasticmachine',
comment_body: '## :broken_heart: Build Failed\n* [continuous-integration/kibana-ci/pull-request](https://kibana-ci.elastic.co/job/elastic-kibana-pull-request/5174/)\n\n' },
{ id: '8438364880',
number: 24158,
owner: 'joshdover',
labels: [],
comment_id: 430786140,
comment_author: 'elasticmachine',
comment_body: '## :broken_heart: Build Failed\n* [continuous-integration/kibana-ci/pull-request](https://kibana-ci.elastic.co/job/elastic-kibana-pull-request/5153/)\n\n' },
{ id: '8438241644',
number: 24104,
owner: 'graphaelli',
labels: [],
comment_id: 430777985,
comment_author: 'elasticmachine',
comment_body: '## :broken_heart: Build Failed\n* [continuous-integration/kibana-ci/pull-request](https://kibana-ci.elastic.co/job/elastic-kibana-pull-request/5150/)\n\n' },
{ id: '8438206753',
number: 24158,
owner: 'joshdover',
labels: [],
comment_id: 430775791,
comment_author: 'elasticmachine',
comment_body: '## :broken_heart: Build Failed\n* [continuous-integration/kibana-ci/pull-request](https://kibana-ci.elastic.co/job/elastic-kibana-pull-request/5147/)\n\n' },
{ id: '8438199856',
number: 23819,
owner: 'mattapperson',
labels: [ ':Beats', 'beats-cm' ],
comment_id: 430775402,
comment_author: 'elasticmachine',
comment_body: '## :broken_heart: Build Failed\n* [continuous-integration/kibana-ci/pull-request](https://kibana-ci.elastic.co/job/elastic-kibana-pull-request/5165/)\n\n' },
{ id: '8438188563',
number: 23648,
owner: 'jbudz',
labels: [ ':Operations' ],
comment_id: 430774756,
comment_author: 'elasticmachine',
comment_body: '## :broken_heart: Build Failed\n* [continuous-integration/kibana-ci/pull-request](https://kibana-ci.elastic.co/job/elastic-kibana-pull-request/5144/)\n\n' },
{ id: '8438183173',
number: 24038,
owner: 'cqliu1',
labels: [ ':Canvas', ':Home', 'review', 'v6.5.0', 'v7.0.0' ],
comment_id: 430774424,
comment_author: 'elasticmachine',
comment_body: '## :broken_heart: Build Failed\n* [continuous-integration/kibana-ci/pull-request](https://kibana-ci.elastic.co/job/elastic-kibana-pull-request/5145/)\n\n' },
{ id: '8438163617',
number: 24100,
owner: 'jakelandis',
labels: [ 'v6.5.0', 'v7.0.0' ],
comment_id: 430773251,
comment_author: 'elasticmachine',
comment_body: '## :broken_heart: Build Failed\n* [continuous-integration/kibana-ci/pull-request](https://kibana-ci.elastic.co/job/elastic-kibana-pull-request/5142/)\n\n' },
{ id: '8438139342',
number: 24153,
owner: 'cchaos',
labels: [ 'backport' ],
comment_id: 430771841,
comment_author: 'elasticmachine',
comment_body: '## :broken_heart: Build Failed\n* [continuous-integration/kibana-ci/pull-request](https://kibana-ci.elastic.co/job/elastic-kibana-pull-request/5143/)\n\n' } ];

View File

@@ -9,7 +9,6 @@ function getBuildStatus({ items: statuses }) {
} }
export default async function getCommitStatus(repo, sha) { export default async function getCommitStatus(repo, sha) {
return cache
const statuses = await repo.commits(sha).statuses.fetch(); const statuses = await repo.commits(sha).statuses.fetch();
const buildStatus = await (async stats => { const buildStatus = await (async stats => {
@@ -21,7 +20,3 @@ export default async function getCommitStatus(repo, sha) {
return buildStatus; return buildStatus;
} }
const cache = { id: 5666338700,
url: 'https://api.github.com/repos/elastic/kibana/statuses/5f948924cc4fe34c7b9399e685927e93a18d7450',
state: 'pending' };

View File

@@ -3,7 +3,7 @@ function formatCommit(commit) {
sha: commit.sha, sha: commit.sha,
owner: commit.committer.login, owner: commit.committer.login,
message: commit.commit.message, message: commit.commit.message,
} };
} }
function formatCommits(commits, lastOnly) { function formatCommits(commits, lastOnly) {
@@ -12,7 +12,6 @@ function formatCommits(commits, lastOnly) {
} }
export default async function getCommits(repo, id, lastOnly = true) { export default async function getCommits(repo, id, lastOnly = true) {
return cache;
const commits = await repo.pulls(id).commits.fetch(); const commits = await repo.pulls(id).commits.fetch();
if (commits.lastPage) { if (commits.lastPage) {
@@ -22,7 +21,3 @@ export default async function getCommits(repo, id, lastOnly = true) {
return formatCommits(commits.items, lastOnly); return formatCommits(commits.items, lastOnly);
} }
const cache = { sha: '5f948924cc4fe34c7b9399e685927e93a18d7450',
owner: 'mattapperson',
message: 'Merge branch \'feature/x-pack/management/beats\' of github.com:elastic/kibana into feature/x-pack/management/beats' };

View File

@@ -1,15 +1,11 @@
export default async function getPull(repo, id) { export default async function getPull(repo, id) {
return cache;
const pull = await repo.pulls(id).fetch(); const pull = await repo.pulls(id).fetch();
return { return {
id: pull.id, id: pull.id,
url: pull.url, url: pull.url,
number: pull.number, number: pull.number,
state: pull.state, state: pull.state,
title: pull.title,
labels: pull.labels.map(label => label.name),
}; };
} }
const cache = { id: 220387229,
url: 'https://api.github.com/repos/elastic/kibana/pulls/23819',
number: 23819,
state: 'open' };