Skip to content

Commit

Permalink
improve filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuyz0112 committed Dec 21, 2023
1 parent 885927a commit 1d71346
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 34 deletions.
44 changes: 22 additions & 22 deletions .github/workflows/create-pr.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# name: Create PR
name: Create PR

# on:
# issues:
# types: [opened, edited, labeled, unlabeled]
# issue_comment:
# types: [created, edited, deleted]
on:
issues:
types: [opened, edited, labeled, unlabeled]
issue_comment:
types: [created, edited, deleted]

# jobs:
# handle_issue:
# runs-on: ubuntu-latest
# name: Create PR
# steps:
# - name: Checkout repository
# uses: actions/checkout@v3
# - name: Setup Deno
# uses: denoland/setup-deno@v1
# with:
# deno-version: 1.38.3
# - name: generate UI
# env:
# GH_TOKEN: ${{ secrets.GH_TOKEN }}
# OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
# run: deno run -A prompts/ui-gen.ts
jobs:
handle_issue:
runs-on: ubuntu-latest
name: Create PR
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: 1.38.3
- name: generate UI
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: deno run -A prompts/ui-gen.ts
2 changes: 1 addition & 1 deletion prompts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function getCode(
messages,
model,
max_tokens: 3000,
temperature: 1,
temperature: 0.2,
});

const codeBlocks: string[] = [];
Expand Down
28 changes: 17 additions & 11 deletions prompts/ui-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { join } from "https://deno.land/[email protected]/path/mod.ts";
import { getCode } from "./common.ts";

type IssueEvent = {
action: string;
issue: {
body: string;
number: number;
Expand Down Expand Up @@ -219,7 +220,7 @@ async function main() {
})
).default;

console.log(githubEvent.issue);
console.log(githubEvent.action, githubEvent.issue);

if (githubEvent.issue.labels.every((l) => l.name !== uiGenLabel)) {
return;
Expand All @@ -229,28 +230,33 @@ async function main() {
return;
}

const isPr = Boolean(githubEvent.issue.pull_request);
const eventName = Deno.env.get("GITHUB_EVENT_NAME");
assert(eventName, "failed to get event name");

// ignore non-comments event in PR
if (isPr && eventName === "issues") {
return;
}

const owner = Deno.env.get("GITHUB_REPOSITORY_OWNER");
assert(owner, "failed to get repo owner");

let repo = Deno.env.get("GITHUB_REPOSITORY");
assert(repo, "failed to get repo name");
repo = repo.replace(`${owner}/`, "");

const branch = `ui-gen-issue-${githubEvent.issue.number}`;
const issue = isPr
? await getConnectedIssue(owner, repo, githubEvent.issue.body)
: githubEvent.issue;

let issue: { number: number; body?: string | null } = {
number: -1,
body: "",
};
let pr: { number: number } = { number: -1 };
const branch = `ui-gen-issue-${issue.number}`;

if (githubEvent.issue.pull_request) {
let pr: { number: number } = { number: -1 };
if (isPr) {
// is PR event
pr = githubEvent.issue;
issue = await getConnectedIssue(owner, repo, githubEvent.issue.body);
} else {
issue = githubEvent.issue;

const connectedPrNumber = await getConnectedPr(owner, repo, issue.number);
pr = connectedPrNumber
? (
Expand Down

0 comments on commit 1d71346

Please sign in to comment.