Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/print workflow runs typo #164

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37978,9 +37978,7 @@ function findSuccessfulCommit(workflow_id, run_id, owner, repo, branch, lastSucc
process.stdout.write('\n');
process.stdout.write(`Workflow Id not provided. Using workflow '${workflow_id}'\n`);
}
// fetch all workflow runs on a given repo/branch/workflow with push and success
const shas = yield octokit
.request(`GET /repos/${owner}/${repo}/actions/workflows/${workflow_id}/runs`, {
const workflowRunsFetchParams = {
owner,
repo,
// on some workflow runs we do not have branch property
Expand All @@ -37991,6 +37989,34 @@ function findSuccessfulCommit(workflow_id, run_id, owner, repo, branch, lastSucc
workflow_id,
event: lastSuccessfulEvent,
status: 'success',
};
function printObjectOneLine(obj) {
let result = '';
for (const [key, value] of Object.entries(obj)) {
result += `${key}: ${value}, `;
}
// Remove the trailing comma and space
result = result.slice(0, -2);
console.log(result);
}
process.stdout.write('\n');
process.stdout.write(`workflowRunsFetchParams\n`);
process.stdout.write(`${printObjectOneLine(workflowRunsFetchParams)}`);
// fetch all workflow runs on a given repo/branch/workflow with push and success
const shas = yield octokit
.request(`GET /repos/${owner}/${repo}/actions/workflows/${workflow_id}/runs`, workflowRunsFetchParams)
.then(({ data: { workflow_runs } }) => {
process.stdout.write('\n');
process.stdout.write(`workflow runs fetch result:\n`);
workflow_runs.forEach((run) => {
process.stdout.write(JSON.stringify({
head_branch: run.head_branch,
head_sha: run.head_sha,
event: run.event,
status: run.status,
}));
});
return workflow_runs;
})
.then(({ data: { workflow_runs } }) => workflow_runs.map((run) => run.head_sha));
return yield findExistingCommit(octokit, branch, shas);
Expand Down
58 changes: 45 additions & 13 deletions find-successful-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,24 +171,56 @@ async function findSuccessfulCommit(
`Workflow Id not provided. Using workflow '${workflow_id}'\n`,
);
}

const workflowRunsFetchParams = {
owner,
repo,
// on some workflow runs we do not have branch property
branch:
lastSuccessfulEvent === 'push' ||
lastSuccessfulEvent === 'workflow_dispatch'
? branch
: undefined,
workflow_id,
event: lastSuccessfulEvent,
status: 'success',
};

function printObjectOneLine(obj) {
let result = '';
for (const [key, value] of Object.entries(obj)) {
result += `${key}: ${value}, `;
}
// Remove the trailing comma and space
result = result.slice(0, -2);
console.log(result);
}

process.stdout.write('\n');
process.stdout.write(`workflowRunsFetchParams\n`);
process.stdout.write(`${printObjectOneLine(workflowRunsFetchParams)}`);

// fetch all workflow runs on a given repo/branch/workflow with push and success
const shas = await octokit
.request(
`GET /repos/${owner}/${repo}/actions/workflows/${workflow_id}/runs`,
{
owner,
repo,
// on some workflow runs we do not have branch property
branch:
lastSuccessfulEvent === 'push' ||
lastSuccessfulEvent === 'workflow_dispatch'
? branch
: undefined,
workflow_id,
event: lastSuccessfulEvent,
status: 'success',
},
workflowRunsFetchParams,
)
.then(({ data: { workflow_runs } }) => {
process.stdout.write('\n');
process.stdout.write(`workflow runs fetch result:\n`);
workflow_runs.forEach((run) => {
process.stdout.write(
JSON.stringify({
head_branch: run.head_branch,
head_sha: run.head_sha,
event: run.event,
status: run.status,
}),
);
});
return workflow_runs;
})
.then(({ data: { workflow_runs } }) =>
workflow_runs.map((run: { head_sha: any }) => run.head_sha),
);
Expand Down
Loading