Skip to content
Open
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
3 changes: 2 additions & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference path="./.next/types/routes.d.ts" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.
File renamed without changes.
24 changes: 10 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"github",
"probot-app"
],
"type": "module",
"release": {
"repositoryUrl": "https://github.com/robvanderleek/create-issue-branch",
"branches": [
Expand Down Expand Up @@ -40,8 +41,8 @@
"dev": "next dev",
"build": "next build",
"compile": "tsc --noemit false",
"test": "jest",
"coverage": "jest --collect-coverage",
"test": "vitest",
"coverage": "vitest --coverage",
"probot:start": "yarn compile && NODE_OPTIONS='--max_old_space_size=490' probot run ./build/probot.js",
"server:start": "yarn compile && NODE_OPTIONS='--max_old_space_size=490' node ./build/server.js",
"action:dist": "yarn compile && esbuild build/action.js --bundle --platform=node --outfile=action-dist/index.js",
Expand All @@ -56,25 +57,25 @@
"mongodb": "^6.20.0",
"next": "^15.5.4",
"node-fetch": "^2.6.1",
"probot": "^13.4.1",
"probot": "^14.2.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"slice": "^1.0.0",
"wildcard-match": "^5.1.3"
},
"devDependencies": {
"@types/jest": "^30.0.0",
"@types/node-fetch": "^2.6.10",
"@types/react": "18.3.13",
"esbuild": "^0.25.10",
"@vercel/node": "^5.3.24",
"jest": "^30.2.0",
"@vitest/coverage-v8": "3.2.4",
"esbuild": "^0.25.10",
"mkver": "^4.3.0",
"nock": "14.0.10",
"nodemon": "^3.1.5",
"smee-client": "^2.0.1",
"ts-jest": "^29.4.4",
"typescript": "^5.9.3"
"smee-client": "^4.3.1",
"typescript": "^5.9.3",
"vite": "^7.1.11",
"vitest": "^3.2.4"
},
"engines": {
"node": ">= 20.x"
Expand All @@ -85,10 +86,5 @@
".env",
"."
]
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"testTimeout": 10000
}
}
2 changes: 1 addition & 1 deletion src/action.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import app from "./probot";
import app from "./probot.ts";

const {run} = require('@probot/adapter-github-actions');

Expand Down
10 changes: 3 additions & 7 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Config, getDefaultConfig} from "./entities/Config";
import {Config, getDefaultConfig} from "./entities/Config.ts";
import {Context} from "probot";

/**
Expand All @@ -9,7 +9,7 @@ const issueTitle = 'Error in Create Issue Branch app configuration'

async function findConfigurationErrorIssue(ctx: Context<any>) {
const fullName = ctx.payload.repository.full_name
const result = await ctx.octokit.search.issuesAndPullRequests(
const result = await ctx.octokit.rest.search.issuesAndPullRequests(
{q: `${issueTitle} repo:${fullName} in:title type:issue state:open`})
return result.data.items
}
Expand All @@ -25,7 +25,7 @@ async function createConfigurationErrorIssue(ctx: Context<any>, err: string) {
`
}
try {
await ctx.octokit.issues.create(ctx.repo({
await ctx.octokit.rest.issues.create(ctx.repo({
title: issueTitle, body: errorBody(err)
}));
} catch (e: any) {
Expand Down Expand Up @@ -93,10 +93,6 @@ export function prSkipCI(config: Config) {
return config.prSkipCI;
}

export function showFreePlanWarning(config: Config) {
return config.freePlanWarning;
}

export function isChatOpsCommand(s?: string) {
if (s) {
const parts = s.trim().toLowerCase().split(/\s/)
Expand Down
40 changes: 20 additions & 20 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import {
getMilestoneNumber,
getRepoName,
getRepoOwnerLogin
} from "./context";
} from "./context.ts";
import {Context, Probot} from "probot";
import {hasValidSubscription} from "./plans";
import {interpolate} from "./interpolate";
import {Config} from "./entities/Config";
import {hasValidSubscription} from "./plans.ts";
import {interpolate} from "./interpolate.ts";
import {Config} from "./entities/Config.ts";
import {
getCommentMessage,
getConventionalPrTitlePrefix,
getDefaultBranch as getDefaultBranchFromConfig,
prSkipCI
} from "./config";
} from "./config.ts";
import {setOutput} from "@actions/core";
import {
formatAsExpandingMarkdown,
Expand All @@ -30,8 +30,8 @@ import {
sleep,
trimStringToByteLength,
wildcardMatch
} from "./utils";
import {GraphQlResponse} from "@octokit/graphql/dist-types/types";
} from "./utils.ts";
import {GraphQlResponse} from "@octokit/graphql/dist-types/types.js";

export async function createIssueBranch(app: Probot, ctx: Context<any>, branchName: string, config: Config) {
if (await hasValidSubscription(app, ctx, config)) {
Expand Down Expand Up @@ -147,12 +147,12 @@ export async function addComment(ctx: Context<any>, config: Config, comment: str
if (!config.silent) {
const params = ctx.issue({body: comment});
try {
await ctx.octokit.issues.createComment(params);
await ctx.octokit.rest.issues.createComment(params);
} catch (e) {
console.info('Creating comment failed, retrying in 1 second');
await sleep(1000);
try {
await ctx.octokit.issues.createComment(params);
await ctx.octokit.rest.issues.createComment(params);
} catch (e) {
console.info('Creating comment failed');
}
Expand All @@ -164,7 +164,7 @@ export async function branchExists(ctx: Context<any>, branchName: string) {
const owner = getRepoOwnerLogin(ctx)
const repo = getRepoName(ctx)
try {
await ctx.octokit.git.getRef({
await ctx.octokit.rest.git.getRef({
owner: owner, repo: repo, ref: `heads/${branchName}`
})
return true
Expand All @@ -177,7 +177,7 @@ export async function deleteBranch(ctx: Context<any>, branchName: string) {
const owner = getRepoOwnerLogin(ctx)
const repo = getRepoName(ctx)
try {
await ctx.octokit.git.deleteRef({
await ctx.octokit.rest.git.deleteRef({
owner: owner, repo: repo, ref: `heads/${branchName}`
})
return true
Expand Down Expand Up @@ -226,7 +226,7 @@ function getDefaultBranch(ctx: Context<any>, config: Config) {

async function getBranchHeadSha(ctx: Context<any>, branch: string) {
try {
const res = await ctx.octokit.git.getRef({
const res = await ctx.octokit.rest.git.getRef({
owner: getRepoOwnerLogin(ctx), repo: getRepoName(ctx), ref: `heads/${branch}`
})
const ref = res.data.object
Expand All @@ -240,7 +240,7 @@ export async function createBranch(app: Probot, ctx: Context<any>, config: Confi
const owner = getRepoOwnerLogin(ctx);
const repo = getRepoName(ctx);
try {
const res = await ctx.octokit.git.createRef({
const res = await ctx.octokit.rest.git.createRef({
owner: owner, repo: repo, ref: `refs/heads/${branchName}`, sha: sha
});
app.log.info(`Branch created: ${branchName}`);
Expand Down Expand Up @@ -277,7 +277,7 @@ export async function createPr(app: Probot, ctx: Context<any>, config: Config, u
app.log.info('Branch and base heads are equal, creating empty commit for PR');
logContext.emptyCommitResponse = await createEmptyCommit(ctx, branchName, getCommitText(ctx, config), String(branchHeadSha));
}
const {data: pr} = await ctx.octokit.pulls.create(
const {data: pr} = await ctx.octokit.rest.pulls.create(
{
owner,
repo,
Expand Down Expand Up @@ -359,7 +359,7 @@ async function getPrBody(app: Probot, ctx: Context<any>, config: Config) {

async function getPullRequestTemplate(ctx: Context<any>): Promise<string | undefined> {
try {
const {data} = await ctx.octokit.repos.getContent({
const {data} = await ctx.octokit.rest.repos.getContent({
owner: getRepoOwnerLogin(ctx),
repo: getRepoName(ctx),
path: '.github/pull_request_template.md'
Expand Down Expand Up @@ -402,23 +402,23 @@ async function copyIssueLabelsToPr(ctx: Context<any>, pr: any) {
const repo = getRepoName(ctx)
const labels = getIssueLabels(ctx)
if (labels.length > 0) {
await ctx.octokit.issues.addLabels({owner, repo, issue_number: pr.number, labels})
await ctx.octokit.rest.issues.addLabels({owner, repo, issue_number: pr.number, labels})
}
}

async function copyIssueAssigneeToPr(ctx: Context<any>, pr: any) {
const owner = getRepoOwnerLogin(ctx)
const repo = getRepoName(ctx)
const assignee = getAssignee(ctx)
await ctx.octokit.issues.addAssignees({owner, repo, issue_number: pr.number, assignees: [assignee]})
await ctx.octokit.rest.issues.addAssignees({owner, repo, issue_number: pr.number, assignees: [assignee]})
}

async function copyIssueMilestoneToPr(ctx: Context<any>, pr: any) {
const owner = getRepoOwnerLogin(ctx)
const repo = getRepoName(ctx)
const number = getMilestoneNumber(ctx)
if (number) {
await ctx.octokit.issues.update({owner, repo, issue_number: pr.number, milestone: number})
await ctx.octokit.rest.issues.update({owner, repo, issue_number: pr.number, milestone: number})
}
}

Expand Down Expand Up @@ -485,7 +485,7 @@ export async function updatePrTitle(app: Probot, ctx: Context<any>, config: Conf
const repo = getRepoName(ctx);
const pullNumber = pr.number;
app.log.info(`Updating title for PR #${pullNumber} in ${owner}/${repo} to: ${updatedTitle}`);
await ctx.octokit.pulls.update({owner: owner, repo: repo, pull_number: pullNumber, title: updatedTitle});
await ctx.octokit.rest.pulls.update({owner: owner, repo: repo, pull_number: pullNumber, title: updatedTitle});
}
}

Expand All @@ -494,5 +494,5 @@ export async function updatePrBody(app: Probot, ctx: Context<any>, config: Confi
const repo = getRepoName(ctx)
const pullNumber = pr.number
app.log.info(`Updating body for PR #${pullNumber} in ${owner}/${repo}`)
await ctx.octokit.pulls.update({owner: owner, repo: repo, pull_number: pullNumber, body: body})
await ctx.octokit.rest.pulls.update({owner: owner, repo: repo, pull_number: pullNumber, body: body})
}
13 changes: 8 additions & 5 deletions src/pages/api/plans.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import {createProbot} from "probot";
import app from "../../probot";
import {listAppSubscriptions} from "../../plans";
import {message} from "../../discord";
import app from "../../probot.ts";
import {listAppSubscriptions} from "../../plans.ts";
import {message} from "../../discord.ts";
import {VercelRequest, VercelResponse} from "@vercel/node";

const probot = createProbot();
const loadingApp = probot.load(app);

export default async function (_: VercelRequest, response: VercelResponse) {
try {
await loadingApp
const subscriptions = await listAppSubscriptions(probot)
await loadingApp;
const octokit = await probot.auth();
const installation = await octokit.rest.apps.getInstallation();
console.log('Authenticated as installation id:', installation.data.id);
const subscriptions = await listAppSubscriptions(octokit)
await message(subscriptions)
response.status(200).json({result: 'OK'})
} catch (error: any) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/webhook.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {createProbot} from "probot";
import app from "../../probot";
import app from "../../probot.ts";
import {VercelRequest, VercelResponse} from "@vercel/node";

const probot = createProbot()
Expand Down
24 changes: 12 additions & 12 deletions src/plans.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Context, Probot} from "probot";
import {getRepoOwnerId, getRepoOwnerLogin, isOrgRepo} from "./context";
import {addComment} from "./github";
import {Config} from "./entities/Config";
import {isRunningInGitHubActions, isRunningInTestEnvironment} from "./utils";
import {Context, Probot, ProbotOctokit} from "probot";
import {getRepoOwnerId, getRepoOwnerLogin, isOrgRepo} from "./context.ts";
import {addComment} from "./github.ts";
import {Config} from "./entities/Config.ts";
import {isRunningInGitHubActions, isRunningInTestEnvironment} from "./utils.ts";

export async function hasValidSubscription(app: Probot, ctx: Context<any>, config: Config) {
if (isRunningInGitHubActions() || isRunningInTestEnvironment()) {
Expand Down Expand Up @@ -35,7 +35,7 @@ export async function isCommercialOrganizationPlan(app: Probot, ctx: Context<any
const login = getRepoOwnerLogin(ctx);
app.log.info(`Checking Marketplace for organization: https://github.com/${login} ...`);
const id = getRepoOwnerId(ctx);
const res = await ctx.octokit.apps.getSubscriptionPlanForAccount({account_id: id});
const res = await ctx.octokit.rest.apps.getSubscriptionPlanForAccount({account_id: id});
const purchase = res.data.marketplace_purchase;
if (purchase.plan && purchase.plan.name === 'Commercial organization') {
app.log.info('Found Commercial organization 💰 plan');
Expand All @@ -54,7 +54,7 @@ export async function isPaidPlan(app: Probot, ctx: Context<any>) {
const login = getRepoOwnerLogin(ctx);
app.log.info(`Checking Marketplace for organization: https://github.com/${login} ...`);
const id = getRepoOwnerId(ctx);
const res = await ctx.octokit.apps.getSubscriptionPlanForAccount({account_id: id});
const res = await ctx.octokit.rest.apps.getSubscriptionPlanForAccount({account_id: id});
const purchase = res.data.marketplace_purchase;
if (purchase.plan && purchase.plan.price_model === 'FREE') {
app.log.info('Found Free plan');
Expand Down Expand Up @@ -112,24 +112,24 @@ export function isFreePaidSubscription(app: Probot, ctx: Context<any>): boolean
}
}

export async function listAppSubscriptions(app: any) {
export async function listAppSubscriptions(octokit: ProbotOctokit) {
let result = ''
const plans = (await app.state.octokit.apps.listPlans()).data
const plans = (await octokit.rest.apps.listPlans()).data
for (const plan of plans) {
if (plan.price_model === 'FLAT_RATE') {
const accounts = await app.state.octokit.paginate(app.state.octokit.apps.listAccountsForPlan,
const accounts = await octokit.paginate(octokit.rest.apps.listAccountsForPlan,
{per_page: 100, plan_id: plan.id}, (response: any) => response.data)
result += `Subscriptions for plan: ${plan.name}\n`
result += '--------------------------------------------------\n'
result += listFreeTrialAccounts(app, accounts)
result += listFreeTrialAccounts(accounts)
result += '--------------------------------------------------\n'
result += `Total: ${accounts.length}\n`
}
}
return result
}

function listFreeTrialAccounts(app: Probot, accounts: Array<any>) {
function listFreeTrialAccounts(accounts: Array<any>) {
let result = ''
for (const account of accounts) {
const purchase = account.marketplace_purchase
Expand Down
Loading