Skip to content

Commit b1a1376

Browse files
authored
Refactoring (#2)
* Refactor src/index.ts * Update dist/index.js
1 parent b88fc88 commit b1a1376

2 files changed

Lines changed: 39 additions & 38 deletions

File tree

dist/index.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29964,38 +29964,40 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
2996429964
const core = __importStar(__nccwpck_require__(7484));
2996529965
const github = __importStar(__nccwpck_require__(3228));
2996629966
async function run() {
29967+
var _a;
2996729968
try {
29968-
// 1. Obtém o token do GitHub
29969+
// Inputs
2996929970
const githubToken = core.getInput('github-token', { required: true });
29970-
// 2. Cria uma instância do cliente Octokit (para interagir com a API)
29971-
const octokit = github.getOctokit(githubToken);
29972-
// 3. Obtém os inputs da action
29973-
const title = core.getInput('title', { required: true });
29974-
const body = core.getInput('body', { required: false });
29975-
const head = core.getInput('source-branch', { required: true });
29976-
const base = core.getInput('dest-branch', { required: true });
29977-
// 4. Obtém informações do repositório
29971+
const title = core.getInput('title', { required: true }).trim();
29972+
const body = ((_a = core.getInput('body', { required: false })) === null || _a === void 0 ? void 0 : _a.trim()) || undefined;
29973+
const sourceBranch = core.getInput('source-branch', { required: true }).trim();
29974+
const destBranch = core.getInput('dest-branch', { required: true }).trim();
29975+
// Repo context
2997829976
const { owner, repo } = github.context.repo;
29979-
// 5. Cria o Pull Request
29977+
const octokit = github.getOctokit(githubToken);
29978+
core.info(`Creating pull request from '${sourceBranch}' to '${destBranch}' in ${owner}/${repo}`);
29979+
// Create PR
2998029980
const { data: pullRequest } = await octokit.rest.pulls.create({
2998129981
owner,
2998229982
repo,
2998329983
title,
29984-
head,
29985-
base,
29986-
body
29984+
head: sourceBranch,
29985+
base: destBranch,
29986+
body,
2998729987
});
29988-
console.log(`Created Pull Request: ${pullRequest.html_url}`);
29989-
// 6. Define o output para uso em actions futuras
29988+
core.info(`Created Pull Request: ${pullRequest.html_url}`);
2999029989
core.setOutput('pull-request-url', pullRequest.html_url);
2999129990
}
2999229991
catch (error) {
2999329992
if (error instanceof Error) {
29994-
core.setFailed(error.message);
29993+
core.setFailed(`Action failed with error: ${error.message}`);
29994+
}
29995+
else {
29996+
core.setFailed('Action failed with unknown error.');
2999529997
}
2999629998
}
2999729999
}
29998-
run();
30000+
void run();
2999930001

3000030002

3000130003
/***/ }),

src/index.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,42 @@
11
import * as core from '@actions/core';
22
import * as github from '@actions/github';
33

4-
async function run() {
4+
async function run(): Promise<void> {
55
try {
6-
// 1. Obtém o token do GitHub
6+
// Inputs
77
const githubToken = core.getInput('github-token', { required: true });
8+
const title = core.getInput('title', { required: true }).trim();
9+
const body = core.getInput('body', { required: false })?.trim() || undefined;
10+
const sourceBranch = core.getInput('source-branch', { required: true }).trim();
11+
const destBranch = core.getInput('dest-branch', { required: true }).trim();
12+
13+
// Repo context
14+
const { owner, repo } = github.context.repo;
815

9-
// 2. Cria uma instância do cliente Octokit (para interagir com a API)
1016
const octokit = github.getOctokit(githubToken);
1117

12-
// 3. Obtém os inputs da action
13-
const title = core.getInput('title', { required: true });
14-
const body = core.getInput('body', { required: false });
15-
const head = core.getInput('source-branch', { required: true });
16-
const base = core.getInput('dest-branch', { required: true });
18+
core.info(`Creating pull request from '${sourceBranch}' to '${destBranch}' in ${owner}/${repo}`);
1719

18-
// 4. Obtém informações do repositório
19-
const { owner, repo } = github.context.repo;
20-
21-
// 5. Cria o Pull Request
20+
// Create PR
2221
const { data: pullRequest } = await octokit.rest.pulls.create({
2322
owner,
2423
repo,
2524
title,
26-
head,
27-
base,
28-
body
25+
head: sourceBranch,
26+
base: destBranch,
27+
body,
2928
});
3029

31-
console.log(`Created Pull Request: ${pullRequest.html_url}`);
32-
33-
// 6. Define o output para uso em actions futuras
30+
core.info(`Created Pull Request: ${pullRequest.html_url}`);
3431
core.setOutput('pull-request-url', pullRequest.html_url);
3532

36-
} catch (error) {
33+
} catch (error: unknown) {
3734
if (error instanceof Error) {
38-
core.setFailed(error.message);
35+
core.setFailed(`Action failed with error: ${error.message}`);
36+
} else {
37+
core.setFailed('Action failed with unknown error.');
3938
}
4039
}
4140
}
4241

43-
run();
42+
void run();

0 commit comments

Comments
 (0)