Skip to content

Commit 25bd979

Browse files
committed
Check all repository by paginate library
1 parent f318804 commit 25bd979

File tree

2 files changed

+82
-20
lines changed

2 files changed

+82
-20
lines changed

dist/index.js

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,50 @@
8383
);
8484
});
8585
};
86+
var __asyncValues =
87+
(this && this.__asyncValues) ||
88+
function (o) {
89+
if (!Symbol.asyncIterator)
90+
throw new TypeError('Symbol.asyncIterator is not defined.');
91+
var m = o[Symbol.asyncIterator],
92+
i;
93+
return m
94+
? m.call(o)
95+
: ((o =
96+
typeof __values === 'function'
97+
? __values(o)
98+
: o[Symbol.iterator]()),
99+
(i = {}),
100+
verb('next'),
101+
verb('throw'),
102+
verb('return'),
103+
(i[Symbol.asyncIterator] = function () {
104+
return this;
105+
}),
106+
i);
107+
function verb(n) {
108+
i[n] =
109+
o[n] &&
110+
function (v) {
111+
return new Promise(function (resolve, reject) {
112+
(v = o[n](v)), settle(resolve, reject, v.done, v.value);
113+
});
114+
};
115+
}
116+
function settle(resolve, reject, d, v) {
117+
Promise.resolve(v).then(function (v) {
118+
resolve({value: v, done: d});
119+
}, reject);
120+
}
121+
};
86122
Object.defineProperty(exports, '__esModule', {value: true});
87123
const auth_app_1 = __nccwpck_require__(7541);
88124
const rest_1 = __nccwpck_require__(5375);
89125
const core = __importStar(__nccwpck_require__(2186));
126+
const plugin_paginate_rest_1 = __nccwpck_require__(4193);
127+
const paginateOctokit = rest_1.Octokit.plugin(
128+
plugin_paginate_rest_1.paginateRest
129+
);
90130
function run() {
91131
return __awaiter(this, void 0, void 0, function* () {
92132
try {
@@ -145,21 +185,40 @@
145185
});
146186
}
147187
function isExistRepositoryInGitHubApps(installationToken, repository) {
188+
var e_1, _a;
148189
return __awaiter(this, void 0, void 0, function* () {
149-
const installationOctokit = new rest_1.Octokit({
190+
const installationOctokit = new paginateOctokit({
150191
auth: installationToken,
151192
baseUrl: process.env.GITHUB_API_URL || 'https://api.github.com',
152193
});
153-
const accessibleRepositories =
154-
yield installationOctokit.apps.listReposAccessibleToInstallation();
155-
const repo = accessibleRepositories.data.repositories.find(
156-
(item) => item.full_name === repository
157-
);
158-
if (repo === undefined) {
159-
throw new Error(
160-
`GitHub Apps can't accessible repository (${repository})`
161-
);
194+
try {
195+
for (
196+
var _b = __asyncValues(
197+
installationOctokit.paginate.iterator(
198+
'GET /installation/repositories'
199+
)
200+
),
201+
_c;
202+
(_c = yield _b.next()), !_c.done;
203+
204+
) {
205+
const response = _c.value;
206+
if (response.data.find((r) => r.full_name === repository)) {
207+
return undefined;
208+
}
209+
}
210+
} catch (e_1_1) {
211+
e_1 = {error: e_1_1};
212+
} finally {
213+
try {
214+
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
215+
} finally {
216+
if (e_1) throw e_1.error;
217+
}
162218
}
219+
throw new Error(
220+
`GitHub Apps can't accessible repository (${repository})`
221+
);
163222
});
164223
}
165224
run();

src/main.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import {Octokit} from '@octokit/rest';
33
import {Endpoints} from '@octokit/types';
44
import * as core from '@actions/core';
55

6+
import {paginateRest} from '@octokit/plugin-paginate-rest';
7+
8+
const paginateOctokit = Octokit.plugin(paginateRest);
9+
610
type listInstallationsResponse =
711
Endpoints['GET /app/installations']['response'];
8-
type listRepositoriesResponse =
9-
Endpoints['GET /installation/repositories']['response'];
1012

1113
async function run(): Promise<void> {
1214
try {
@@ -67,19 +69,20 @@ async function isExistRepositoryInGitHubApps(
6769
installationToken: string,
6870
repository: string
6971
): Promise<void> {
70-
const installationOctokit = new Octokit({
72+
const installationOctokit = new paginateOctokit({
7173
auth: installationToken,
7274
baseUrl: process.env.GITHUB_API_URL || 'https://api.github.com',
7375
});
74-
const accessibleRepositories: listRepositoriesResponse =
75-
await installationOctokit.apps.listReposAccessibleToInstallation();
7676

77-
const repo = accessibleRepositories.data.repositories.find(
78-
(item) => item.full_name === repository
79-
);
80-
if (repo === undefined) {
81-
throw new Error(`GitHub Apps can't accessible repository (${repository})`);
77+
for await (const response of installationOctokit.paginate.iterator(
78+
'GET /installation/repositories'
79+
)) {
80+
if (response.data.find((r) => r.full_name === repository)) {
81+
return undefined;
82+
}
8283
}
84+
85+
throw new Error(`GitHub Apps can't accessible repository (${repository})`);
8386
}
8487

8588
run();

0 commit comments

Comments
 (0)