repo-branch 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +22 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -49,8 +49,10 @@ const fs = __importStar(require("fs"));
|
|
|
49
49
|
dotenv_1.default.config({ quiet: true });
|
|
50
50
|
const program = new commander_1.Command();
|
|
51
51
|
// Configuration - load from environment variables
|
|
52
|
+
const GITHUB_ORG = process.env.BRANCH_SYNC_GITHUB_ORG || "";
|
|
52
53
|
const GITHUB_OWNER = process.env.BRANCH_SYNC_GITHUB_OWNER || "";
|
|
53
54
|
const GITHUB_TOKEN = process.env.BRANCH_SYNC_GITHUB_TOKEN || "";
|
|
55
|
+
const OWNER = GITHUB_ORG || GITHUB_OWNER;
|
|
54
56
|
// Function to check if .env file exists
|
|
55
57
|
function checkEnvFile() {
|
|
56
58
|
const envPath = path.resolve(process.cwd(), ".env");
|
|
@@ -58,9 +60,9 @@ function checkEnvFile() {
|
|
|
58
60
|
}
|
|
59
61
|
// Function to validate environment variables
|
|
60
62
|
function validateEnv() {
|
|
61
|
-
if (!
|
|
62
|
-
console.error(chalk_1.default.red("❌ BRANCH_SYNC_GITHUB_OWNER
|
|
63
|
-
console.error(chalk_1.default.yellow("Please set BRANCH_SYNC_GITHUB_OWNER in your .env file or as environment variable"));
|
|
63
|
+
if (!OWNER) {
|
|
64
|
+
console.error(chalk_1.default.red("❌ Neither BRANCH_SYNC_GITHUB_ORG nor BRANCH_SYNC_GITHUB_OWNER found in environment variables"));
|
|
65
|
+
console.error(chalk_1.default.yellow("Please set either BRANCH_SYNC_GITHUB_ORG or BRANCH_SYNC_GITHUB_OWNER in your .env file or as environment variable"));
|
|
64
66
|
return false;
|
|
65
67
|
}
|
|
66
68
|
if (!GITHUB_TOKEN) {
|
|
@@ -82,15 +84,22 @@ if (!validateEnv()) {
|
|
|
82
84
|
const octokit = new rest_1.Octokit({ auth: GITHUB_TOKEN });
|
|
83
85
|
async function getRepositories() {
|
|
84
86
|
try {
|
|
85
|
-
const repos =
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
const repos = !!GITHUB_ORG
|
|
88
|
+
? await octokit.paginate(octokit.rest.repos.listForOrg, {
|
|
89
|
+
org: OWNER,
|
|
90
|
+
username: OWNER,
|
|
91
|
+
per_page: 100,
|
|
92
|
+
sort: "full_name",
|
|
93
|
+
})
|
|
94
|
+
: await octokit.paginate(octokit.rest.repos.listForAuthenticatedUser, {
|
|
95
|
+
username: OWNER,
|
|
96
|
+
per_page: 100,
|
|
97
|
+
sort: "full_name",
|
|
98
|
+
});
|
|
91
99
|
return repos.map((repo) => ({
|
|
92
100
|
name: repo.name,
|
|
93
101
|
defaultBranch: repo.default_branch ?? "main",
|
|
102
|
+
full_name: repo.full_name,
|
|
94
103
|
}));
|
|
95
104
|
}
|
|
96
105
|
catch (error) {
|
|
@@ -101,12 +110,12 @@ async function getRepositories() {
|
|
|
101
110
|
async function createBranch(repoName, branchName) {
|
|
102
111
|
try {
|
|
103
112
|
const { data: refData } = await octokit.rest.git.getRef({
|
|
104
|
-
owner:
|
|
113
|
+
owner: OWNER,
|
|
105
114
|
repo: repoName,
|
|
106
|
-
ref: `heads/${(await octokit.rest.repos.get({ owner:
|
|
115
|
+
ref: `heads/${(await octokit.rest.repos.get({ owner: OWNER, repo: repoName })).data.default_branch}`,
|
|
107
116
|
});
|
|
108
117
|
await octokit.rest.git.createRef({
|
|
109
|
-
owner:
|
|
118
|
+
owner: OWNER,
|
|
110
119
|
repo: repoName,
|
|
111
120
|
ref: `refs/heads/${branchName}`,
|
|
112
121
|
sha: refData.object.sha,
|
|
@@ -126,7 +135,7 @@ async function selectRepositories(repos) {
|
|
|
126
135
|
name: "selectedRepos",
|
|
127
136
|
message: "Select repositories:",
|
|
128
137
|
choices: repos.map((repo) => ({
|
|
129
|
-
name: `${repo.
|
|
138
|
+
name: `${repo.full_name} (${repo.defaultBranch})`,
|
|
130
139
|
value: repo,
|
|
131
140
|
})),
|
|
132
141
|
pageSize: 15,
|