Skip to content
Merged
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
31 changes: 16 additions & 15 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29963,17 +29963,18 @@ var __importStar = (this && this.__importStar) || (function () {
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__nccwpck_require__(7484));
const github = __importStar(__nccwpck_require__(3228));
/**
* Main asynchronous function.
* @returns {Promise<void>}
*/
async function run() {
try {
// 1. Obter os inputs
const owner = core.getInput('owner', { required: true });
const repo = core.getInput('repo', { required: true });
const baseBranch = core.getInput('base-branch', { required: true });
const newBranch = core.getInput('new-branch', { required: true });
const githubToken = core.getInput('github-token', { required: true });
// 2. Inicializar o cliente Octokit (para interagir com a API do GitHub)
const githubToken = core.getInput('github-token', { required: true }).trim();
const owner = core.getInput('owner', { required: true }).trim();
const repo = core.getInput('repo', { required: true }).trim();
const baseBranch = core.getInput('base-branch', { required: true }).trim();
const newBranch = core.getInput('new-branch', { required: true }).trim();
const octokit = github.getOctokit(githubToken);
// 3. Obter o SHA do commit da base-branch
core.info(`-> Trying to get the SHA for the base branch: ${baseBranch}`);
const { data: baseBranchData } = await octokit.rest.git.getRef({
owner,
Expand All @@ -29982,26 +29983,26 @@ async function run() {
});
const sha = baseBranchData.object.sha;
core.info(`<- SHA of the base branch (${baseBranch}) successfully obtained: ${sha}`);
// 4. Criar a nova branch (referência)
core.info(`-> Creating the new branch: ${newBranch} with SHA: ${sha}`);
await octokit.rest.git.createRef({
owner,
repo,
ref: `refs/heads/${newBranch}`, // 'refs/heads/' é necessário para criar novas branches
sha: sha,
});
// 5. Sucesso
core.setOutput('success-message', `Branch '${newBranch}' created successfully in the repository '${owner}/${repo}' from '${baseBranch}'.`);
core.info('Operation completed successfully!');
}
catch (error) {
// 6. Falha
core.setFailed(error.message);
core.error(`Failed to create branch: ${error.message}`);
if (error instanceof Error) {
core.setFailed(`Action failed due to error: ${error.message}`);
}
else {
core.setFailed('Action failed with an unknown error.');
}
}
}
// Executar a função principal
run();
void run();


/***/ }),
Expand Down
39 changes: 20 additions & 19 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
import * as core from '@actions/core';
import * as github from '@actions/github';

async function run() {
/**
* Main asynchronous function.
* @returns {Promise<void>}
*/
async function run(): Promise<void> {
try {
// 1. Obter os inputs
const owner = core.getInput('owner', { required: true });
const repo = core.getInput('repo', { required: true });
const baseBranch = core.getInput('base-branch', { required: true });
const newBranch = core.getInput('new-branch', { required: true });
const githubToken = core.getInput('github-token', { required: true });

// 2. Inicializar o cliente Octokit (para interagir com a API do GitHub)
const githubToken: string = core.getInput('github-token', { required: true }).trim();
const owner: string = core.getInput('owner', { required: true }).trim();
const repo: string = core.getInput('repo', { required: true }).trim();
const baseBranch: string = core.getInput('base-branch', { required: true }).trim();
const newBranch: string = core.getInput('new-branch', { required: true }).trim();

const octokit = github.getOctokit(githubToken);

// 3. Obter o SHA do commit da base-branch
core.info(`-> Trying to get the SHA for the base branch: ${baseBranch}`);

const { data: baseBranchData } = await octokit.rest.git.getRef({
owner,
repo,
ref: `heads/${baseBranch}`, // 'heads/' é necessário para referências de branches
});

const sha = baseBranchData.object.sha;

core.info(`<- SHA of the base branch (${baseBranch}) successfully obtained: ${sha}`);

// 4. Criar a nova branch (referência)
core.info(`-> Creating the new branch: ${newBranch} with SHA: ${sha}`);

await octokit.rest.git.createRef({
Expand All @@ -34,16 +35,16 @@ async function run() {
sha: sha,
});

// 5. Sucesso
core.setOutput('success-message', `Branch '${newBranch}' created successfully in the repository '${owner}/${repo}' from '${baseBranch}'.`);
core.info('Operation completed successfully!');

} catch (error: any) {
// 6. Falha
core.setFailed(error.message);
core.error(`Failed to create branch: ${error.message}`);
} catch (error: unknown) {
if (error instanceof Error) {
core.setFailed(`Action failed due to error: ${error.message}`);
} else {
core.setFailed('Action failed with an unknown error.');
}
}
}

// Executar a função principal
run();
void run();