Skip to content

Commit bb8044a

Browse files
committed
refactor: save repo api request
1 parent 1119d1a commit bb8044a

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

.dockerignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@ coverage
33
npm-debug.log
44
*.pem
55
.env
6-
.*
6+
.*
7+
docker-compose.yml
8+
Dockerfile
9+
*.md
10+
.gitignore
11+
.dockerignore

src/utils/get-pull-config.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Logger, ProbotOctokit } from "probot";
22
import { appConfig } from "@/src/configs/app-config.ts";
33
import { SchedulerJobData } from "@wei/probot-scheduler";
44
import { PullConfig, pullConfigSchema } from "@/src/utils/schema.ts";
5+
import { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods";
56

67
async function getLivePullConfig(
78
octokit: ProbotOctokit,
@@ -34,24 +35,16 @@ async function getLivePullConfig(
3435
return result.data;
3536
}
3637

37-
async function getDefaultPullConfig(
38-
octokit: ProbotOctokit,
38+
function getDefaultPullConfig(
39+
repository: RestEndpointMethodTypes["repos"]["get"]["response"]["data"],
3940
log: Logger,
40-
jobData: SchedulerJobData,
41-
): Promise<PullConfig | null> {
41+
): PullConfig | null {
4242
log.debug(`⚙️ Fetching default config`);
4343

44-
const { owner, repo } = jobData;
45-
46-
const repoInfo = await octokit.repos.get({
47-
owner,
48-
repo,
49-
});
50-
51-
if (repoInfo.data && repoInfo.data.fork && repoInfo.data.parent) {
52-
const upstreamOwner = repoInfo.data.parent.owner &&
53-
repoInfo.data.parent.owner.login;
54-
const defaultBranch = repoInfo.data.parent.default_branch;
44+
if (repository.fork && repository.parent) {
45+
const upstreamOwner = repository.parent.owner &&
46+
repository.parent.owner.login;
47+
const defaultBranch = repository.parent.default_branch;
5548

5649
if (upstreamOwner && defaultBranch) {
5750
log.debug(
@@ -101,7 +94,7 @@ export async function getPullConfig(
10194
if (!config && !repository.fork) {
10295
return null; // TODO Cancel scheduled job
10396
} else if (!config) {
104-
config = await getDefaultPullConfig(octokit, log, jobData);
97+
config = getDefaultPullConfig(repository, log);
10598
}
10699

107100
return config;

0 commit comments

Comments
 (0)