Skip to content

Commit

Permalink
BREAKING(action): disable a default value for labels option
Browse files Browse the repository at this point in the history
  • Loading branch information
hasundue committed Oct 28, 2022
1 parent af09749 commit 9c57f14
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 35 deletions.
1 change: 1 addition & 0 deletions .github/workflows/denopendabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ jobs:
mode: app
exclude: integration/src/deps.ts
auto-merge: any
labels: dependencies
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
with:
mode: app
release: ${{ steps.run.outputs.version }}
auto-merge: all
auto-merge: any
14 changes: 11 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ inputs:
labels:
description: Labels for the pull request (space-separated)
required: false
default: dependencies

release:
description: Bump the project version to this value for a release
required: false

auto-merge:
description: Merge a pull request automaticaly ('any', for App)
description: Merge a pull request automaticaly ('any' or null, for App)
required: false

outputs:
Expand All @@ -70,7 +69,16 @@ runs:
uses: peter-evans/repository-dispatch@v2
with:
event-type: denopendabot-run
client-payload: ${{ toJSON(inputs) }}
client-payload: >
{
"baseBranch": "${{ inputs.base-branch }}",
"workingBranch": "${{ inputs.working-branch }}",
"include": "${{ inputs.include }}",
"exclude": "${{ inputs.exclude }}",
"labels": "${{ inputs.labels }}",
"release": "${{ inputs.release }}",
"autoMerge": "${{ inputs.auto-merge }}"
}
- name: Setup Deno
if: ${{ inputs.mode == 'action' }}
Expand Down
2 changes: 1 addition & 1 deletion app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ app.use("*", async (context, next) => {
if (deploy === "production") {
const staging = await location("staging");
await fetch(staging + "api/github/webhooks", context.req.clone());
console.log(`transfered the request to ${staging}`);
console.debug(`transfered the request to ${staging}`);
}
await next();
});
Expand Down
43 changes: 18 additions & 25 deletions app/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,17 @@ type Context = {
};

type ClientPayloadKeys =
| "mode"
| "repository"
| "base-branch"
| "working-branch"
| "auto-merge"
| "baseBranch"
| "workingBranch"
| "autoMerge"
| "labels"
| "include"
| "exclude"
| "release";

type ClientPayload = Partial<
{
[K in ClientPayloadKeys]: string;
}
>;
type ClientPayload = {
[K in ClientPayloadKeys]: string;
};

if (!privateKey) {
throw Error("Private key is not deployed on Upstash Redis.");
Expand All @@ -55,7 +51,7 @@ const app = new App({

const getContext = async (payload: PayLoadWithRepository) => {
const deploy = await deployment();
console.log(`deployment: ${deploy}`);
console.debug(`deployment: ${deploy}`);

const owner = payload.repository.owner.login;
const repo = payload.repository.name;
Expand Down Expand Up @@ -83,8 +79,8 @@ app.webhooks.on("repository_dispatch", async ({ octokit, payload }) => {
if (payload.action !== "denopendabot-run") return;

const context = await getContext(payload);
const inputs: ClientPayload = payload.client_payload;
const branch = inputs["working-branch"] ?? "denopendabot";
const inputs = payload.client_payload as ClientPayload;
const branch = inputs.workingBranch ?? "denopendabot";
console.log(`branch: ${branch}`);

if (!associated(context, branch)) return;
Expand All @@ -93,22 +89,19 @@ app.webhooks.on("repository_dispatch", async ({ octokit, payload }) => {

const repository = payload.repository.full_name;

const labels = inputs.labels?.split(" ") ?? [];
const labels = inputs.labels ? inputs.labels.split(" ") : [];

if (isTest(context, branch)) {
labels.push("test");
}
if (inputs["auto-merge"]) {
labels.push("auto-merge");
}
if (isTest(context, branch)) labels.push("test");
if (inputs.release) labels.push("release");
if (inputs.autoMerge) labels.push("auto-merge");

const options: denopendabot.Options = {
octokit,
baseBranch: inputs["base-branch"],
workingBranch: inputs["working-branch"],
include: inputs.include?.split(" "),
exclude: inputs.exclude?.split(" "),
release: inputs.release,
baseBranch: inputs.baseBranch,
workingBranch: inputs.workingBranch,
include: inputs.include ? inputs.include.split(" ") : undefined,
exclude: inputs.exclude ? inputs.exclude.split(" ") : undefined,
release: inputs.release ?? undefined,
};

const updates = await denopendabot.getUpdates(repository, options);
Expand Down
12 changes: 7 additions & 5 deletions mod/octokit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export class GitHubClient {
base: string,
branch: string,
title: string,
labels = ["dependencies"],
labels?: string[],
) {
const [owner, repo] = repository.split("/");

Expand All @@ -240,10 +240,12 @@ export class GitHubClient {
);

// add a label if given
await this.octokit.request(
"POST /repos/{owner}/{repo}/issues/{issue_number}/labels",
{ owner, repo, issue_number: result.number, labels },
);
if (labels) {
await this.octokit.request(
"POST /repos/{owner}/{repo}/issues/{issue_number}/labels",
{ owner, repo, issue_number: result.number, labels },
);
}

console.log(`🚀 Created a pull request "${result.title}"`);

Expand Down

0 comments on commit 9c57f14

Please sign in to comment.