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

artifact download findBy to query other workflow #333

Merged
merged 2 commits into from
Jun 25, 2024
Merged
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
31 changes: 23 additions & 8 deletions packages/action/src/comment/postGithubCommentFromArtifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import type { Logger } from "@covector/types";
export function* postGithubCommentFromArtifact({
logger,
octokit,
token,
payload,
}: {
logger: Logger;
octokit: InstanceType<typeof GitHub>;
token: string;
payload: WorkflowRunEvent;
}): Operation<void> {
const {
Expand All @@ -22,22 +24,28 @@ export function* postGithubCommentFromArtifact({
owner: { login: owner },
},
} = payload;
const allArtifacts = yield octokit.rest.actions.listWorkflowRunArtifacts({
owner: owner,
repo: repo,

const artifacts = yield octokit.rest.actions.listWorkflowRunArtifacts({
owner,
repo,
run_id: payload.workflow_run.id,
});

// download the artifact from `pull_request` workflow that generated it
const commentArtifact = allArtifacts.data.artifacts.filter((artifact) => {
const commentArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "covector-comment";
})[0];

const artifact = new DefaultArtifactClient();
const artifactRoot = process.env.RUNNER_TEMP ?? "..";
// this is required to elevate iternal permissions to fetch artifacts from another workflow
const findBy = {
token,
workflowRunId: payload.workflow_run.id,
repositoryOwner: owner,
repositoryName: repo,
};
const { downloadPath } = yield artifact.downloadArtifact(commentArtifact.id, {
// optional: download destination path. otherwise defaults to $GITHUB_WORKSPACE
path: artifactRoot,
findBy,
});

const comment = yield fs.readFile(
Expand All @@ -52,5 +60,12 @@ export function* postGithubCommentFromArtifact({
);
const prNumber = parseInt(prNumberAsString, 10);

yield postGithubComment({ logger, comment, octokit, repo, owner, prNumber });
yield postGithubComment({
logger,
comment,
octokit,
repo,
owner,
prNumber,
});
}
7 changes: 6 additions & 1 deletion packages/action/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ export function* run(logger: Logger): Generator<any, any, any> {
if (github.context.eventName === "workflow_run") {
const octokit = github.getOctokit(token);
const payload = github.context.payload as WorkflowRunEvent;
yield postGithubCommentFromArtifact({ logger, octokit, payload });
yield postGithubCommentFromArtifact({
logger,
octokit,
token,
payload,
});
} else {
const covectored: CovectorStatus = yield covector({
logger,
Expand Down
Loading