From 49cc589727f372b951f25870f522390b02a22b71 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Tue, 27 Jul 2021 09:52:02 +0300 Subject: [PATCH] github list prs: Added check summary if exists --- github_list_own_prs_in_repo.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/github_list_own_prs_in_repo.js b/github_list_own_prs_in_repo.js index cdb55f2..c8ad872 100644 --- a/github_list_own_prs_in_repo.js +++ b/github_list_own_prs_in_repo.js @@ -23,7 +23,8 @@ "Content-Type": "application/json", "Authorization": `token ${GITHUB_AUTH}` }, - "body": "{\"query\":\"{\\n user(login: \\\"" + GITHUB_USERNAME + "\\\") {\\n pullRequests(first: 100, states: OPEN, baseRefName:\\\"master\\\") {\\n totalCount\\n nodes {\\n createdAt\\n number\\n title\\n mergeable\\n url\\n labels(first: 10){\\n nodes{\\n color\\n description\\n name\\n \\n }\\n }\\n commits(last:1) {\\n nodes {\\n commit {\\n statusCheckRollup{\\n state\\n }\\n }\\n }\\n }\\n baseRefName\\n headRefName\\n repository{\\n nameWithOwner\\n }\\n }\\n pageInfo {\\n hasNextPage\\n endCursor\\n }\\n }\\n }\\n}\"}" + // "body": "{\"query\":\"{\\n user(login: \\\"" + GITHUB_USERNAME + "\\\") {\\n pullRequests(first: 100, states: OPEN, baseRefName:\\\"master\\\") {\\n totalCount\\n nodes {\\n createdAt\\n number\\n title\\n mergeable\\n url\\n labels(first: 10){\\n nodes{\\n color\\n description\\n name\\n \\n }\\n }\\n commits(last:1) {\\n nodes {\\n commit {\\n statusCheckRollup{\\n state\\n }\\n }\\n }\\n }\\n baseRefName\\n headRefName\\n repository{\\n nameWithOwner\\n }\\n }\\n pageInfo {\\n hasNextPage\\n endCursor\\n }\\n }\\n }\\n}\"}" + "body": "{\"query\":\"{\\n user(login: \\\"" + GITHUB_USERNAME + "\\\") {\\n pullRequests(first: 100, states: OPEN ) {\\n totalCount\\n nodes {\\n updatedAt\\n createdAt\\n number\\n title\\n mergeable\\n url\\n labels(first: 10){\\n nodes{\\n color\\n description\\n name\\n \\n }\\n }\\n commits(last:1) {\\n nodes {\\n commit {\\n statusCheckRollup{\\n state\\n contexts(last:40){\\n nodes {\\n ... on StatusContext{\\n state\\n context\\n description\\n }\\n }\\n }\\n }\\n }\\n }\\n }\\n baseRefName\\n headRefName\\n repository{\\n nameWithOwner\\n }\\n }\\n pageInfo {\\n hasNextPage\\n endCursor\\n }\\n }\\n }\\n}\"}" }); const payload = await response.json(); const prs = payload.data.user.pullRequests.nodes.filter(pr => { @@ -61,6 +62,12 @@ const div = document.createElement('div'); const prState = pr.commits.nodes[0].commit.statusCheckRollup?.state || ''; const prStateColor = prState === 'FAILURE' ? 'red' : (prState === 'SUCCESS' ? 'green' : 'yellow'); + const checksSum = pr.commits.nodes[0].commit.statusCheckRollup?.contexts.nodes.reduce((acc, check) => { + acc.total++; + if(check.state === 'SUCCESS') acc.success++; + return acc; + }, {total:0, success:0}); + const checksSumStr = checksSum ? `Checks Passed: ${checksSum.success} / ${checksSum.total}` : ''; div.id = generatePrItemId(pr.number); div.onclick = () => { window.open(pr.url, '_blank'); @@ -92,6 +99,7 @@
${lblInnerHtml}
+ ${checksSumStr} `; return div;