Attempt to contact API
This commit is contained in:
parent
7610a5919d
commit
981ae5538b
@ -4,5 +4,5 @@ outputs:
|
||||
url:
|
||||
description: 'The URL of the deployed branch'
|
||||
runs:
|
||||
using: node20
|
||||
using: node16
|
||||
main: dist/index.js
|
||||
|
13
dist/index.js
vendored
13
dist/index.js
vendored
@ -42,6 +42,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
const core = __importStar(__nccwpck_require__(7484));
|
||||
const gitea = __importStar(__nccwpck_require__(3228));
|
||||
const client = __importStar(__nccwpck_require__(8486));
|
||||
const fetch = __importStar(__nccwpck_require__(4844));
|
||||
function main() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const branchName = gitea.context.ref;
|
||||
@ -57,7 +58,8 @@ function main() {
|
||||
core.info(`process.env[${key}]`);
|
||||
});
|
||||
const api = client.default({
|
||||
baseUrl: process.env.GITHUB_API_URL,
|
||||
fetch: httpClientFetch,
|
||||
baseUrl: gitea.context.apiUrl,
|
||||
headers: {
|
||||
["Authorization"]: `token ${process.env.GITHUB_TOKEN}`
|
||||
}
|
||||
@ -74,7 +76,7 @@ function main() {
|
||||
core.info(`Repository: ${data.updated_at}`);
|
||||
}
|
||||
if (error) {
|
||||
core.error(`Error fetching repository: ${error}`);
|
||||
core.error(`Error fetching repository: ${JSON.stringify(error)}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -84,6 +86,13 @@ function handleError(err) {
|
||||
console.error(err);
|
||||
core.setFailed(`Unhandled error: ${err}`);
|
||||
}
|
||||
function httpClientFetch(request) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const httpClient = new fetch.HttpClient();
|
||||
const response = yield httpClient.request(request.method, request.url, request.body, request.headers);
|
||||
return Object.assign(Object.assign({}, response), { ok: response.message.statusCode && response.message.statusCode >= 200 && response.message.statusCode < 300, json: () => response.readBody().then(JSON.parse), headers: { get: (key) => response.message.headers[key] }, text: () => response.readBody() });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
60
package-lock.json
generated
60
package-lock.json
generated
@ -11,11 +11,12 @@
|
||||
"@actions/core": "^1.11.1",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@actions/github": "^6.0.0",
|
||||
"@actions/http-client": "^2.2.3",
|
||||
"openapi-fetch": "^0.12.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.12.0",
|
||||
"@types/node": "^20.14.8",
|
||||
"@types/node": "^16.11.7",
|
||||
"@vercel/ncc": "^0.38.2",
|
||||
"eslint": "^9.12.0",
|
||||
"globals": "^15.11.0",
|
||||
@ -605,6 +606,26 @@
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/@redocly/openapi-core/node_modules/node-fetch": {
|
||||
"version": "2.7.0",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
|
||||
"integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"whatwg-url": "^5.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "4.x || >=6.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"encoding": "^0.1.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"encoding": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@types/estree": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz",
|
||||
@ -618,13 +639,10 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "20.16.11",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.16.11.tgz",
|
||||
"integrity": "sha512-y+cTCACu92FyA5fgQSAI8A1H429g7aSK2HsO7K4XYUWc4dY5IUz55JSDIYT6/VsOLfGy8vmvQYC2hfb0iF16Uw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"undici-types": "~6.19.2"
|
||||
}
|
||||
"version": "16.18.113",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.113.tgz",
|
||||
"integrity": "sha512-4jHxcEzSXpF1cBNxogs5FVbVSFSKo50sFCn7Xg7vmjJTbWFWgeuHW3QnoINlfmfG++MFR/q97RZE5RQXKeT+jg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@typescript-eslint/eslint-plugin": {
|
||||
"version": "8.8.1",
|
||||
@ -1615,26 +1633,6 @@
|
||||
"integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/node-fetch": {
|
||||
"version": "2.7.0",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
|
||||
"integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"whatwg-url": "^5.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "4.x || >=6.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"encoding": "^0.1.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"encoding": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/once": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
@ -2070,12 +2068,6 @@
|
||||
"node": ">=14.0"
|
||||
}
|
||||
},
|
||||
"node_modules/undici-types": {
|
||||
"version": "6.19.8",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz",
|
||||
"integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/universal-user-agent": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-6.0.1.tgz",
|
||||
|
@ -21,11 +21,12 @@
|
||||
"@actions/core": "^1.11.1",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@actions/github": "^6.0.0",
|
||||
"@actions/http-client": "^2.2.3",
|
||||
"openapi-fetch": "^0.12.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.12.0",
|
||||
"@types/node": "^20.14.8",
|
||||
"@types/node": "^16.11.7",
|
||||
"@vercel/ncc": "^0.38.2",
|
||||
"eslint": "^9.12.0",
|
||||
"globals": "^15.11.0",
|
||||
|
20
src/main.ts
20
src/main.ts
@ -2,6 +2,7 @@ import * as core from '@actions/core';
|
||||
import * as gitea from '@actions/github';
|
||||
import * as client from 'openapi-fetch';
|
||||
import * as specification from "./gitea-api";
|
||||
import * as fetch from "@actions/http-client";
|
||||
|
||||
async function main() {
|
||||
const branchName = gitea.context.ref;
|
||||
@ -22,7 +23,8 @@ async function main() {
|
||||
});
|
||||
|
||||
const api = client.default<specification.paths>({
|
||||
baseUrl: process.env.GITHUB_API_URL,
|
||||
fetch: httpClientFetch,
|
||||
baseUrl: gitea.context.apiUrl,
|
||||
headers: {
|
||||
["Authorization"]: `token ${process.env.GITHUB_TOKEN}`
|
||||
}
|
||||
@ -39,7 +41,7 @@ async function main() {
|
||||
core.info(`Repository: ${data.updated_at}`);
|
||||
}
|
||||
if (error) {
|
||||
core.error(`Error fetching repository: ${error}`);
|
||||
core.error(`Error fetching repository: ${JSON.stringify(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,3 +52,17 @@ function handleError(err: any): void {
|
||||
console.error(err)
|
||||
core.setFailed(`Unhandled error: ${err}`)
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
async function httpClientFetch(request: any): Promise<any> {
|
||||
const httpClient = new fetch.HttpClient();
|
||||
const response = await httpClient.request(request.method, request.url, request.body, request.headers);
|
||||
return {
|
||||
ok: response.message.statusCode && response.message.statusCode >= 200 && response.message.statusCode < 300,
|
||||
headers: {
|
||||
get: (headerName: string) => response.message.headers[headerName]
|
||||
},
|
||||
json: () => response.readBody().then(JSON.parse),
|
||||
text: () => response.readBody()
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user