-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
160 lines (150 loc) · 4.59 KB
/
cli.js
File metadata and controls
160 lines (150 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env node
// filepath: d:\Projects\Personal\IssueSync\cli.js
require("dotenv").config();
const yargs = require("yargs/yargs");
const { hideBin } = require("yargs/helpers");
const issueSync = require("./lib");
// Command line interface setup
const argv = yargs(hideBin(process.argv))
.command("list", "List issues from a GitHub repository", (yargs) => {
return yargs
.option("owner", {
alias: "o",
describe: "Repository owner",
type: "string",
demandOption: true,
})
.option("repo", {
alias: "r",
describe: "Repository name",
type: "string",
demandOption: true,
})
.option("state", {
alias: "s",
describe: "Issue state (open, closed, all)",
type: "string",
default: "open",
})
.option("labels", {
alias: "l",
describe: "Filter by labels (comma-separated)",
type: "string",
})
.option("verbose", {
alias: "v",
describe: "Show more details",
type: "boolean",
default: false,
});
})
.command("sync", "Synchronize issues between repositories", (yargs) => {
return yargs
.option("source-owner", {
describe: "Source repository owner",
type: "string",
demandOption: true,
})
.option("source-repo", {
describe: "Source repository name",
type: "string",
demandOption: true,
})
.option("target-owner", {
describe: "Target repository owner",
type: "string",
demandOption: true,
})
.option("target-repo", {
describe: "Target repository name",
type: "string",
demandOption: true,
})
.option("state", {
alias: "s",
describe: "Issues state to sync (open, closed, all)",
type: "string",
default: "open",
})
.option("labels", {
alias: "l",
describe: "Filter issues by labels (comma-separated)",
type: "string",
})
.option("sync-comments", {
describe: "Sync issue comments",
type: "boolean",
default: true,
});
})
.demandCommand(1, "You need to specify a command")
.help().argv;
// Initialize the GitHub client
issueSync.init();
// Execute commands based on user input
const command = argv._[0];
if (command === "list") {
(async () => {
try {
const issues = await issueSync.listIssues({
owner: argv.owner,
repo: argv.repo,
state: argv.state,
labels: argv.labels,
verbose: argv.verbose,
});
if (!issues.length) {
console.log("No issues found.");
} else {
console.log(`📋 Found ${issues.length} issues for ${argv.owner}/${argv.repo}:`);
issues.forEach((issue) => {
const labels = issue.labels.map((label) => `[${label.name}]`).join(" ");
console.log(`#${issue.number} - ${issue.title} ${labels}`);
if (argv.verbose) {
console.log(` State: ${issue.state}`);
console.log(` Created: ${new Date(issue.created_at).toLocaleDateString()}`);
console.log(` Comments: ${issue.comments}`);
console.log(` URL: ${issue.html_url}`);
console.log("");
}
});
}
} catch (error) {
console.error(error.message);
process.exit(1);
}
})();
} else if (command === "sync") {
(async () => {
try {
console.log(
`Synchronizing issues from ${argv["source-owner"]}/${argv["source-repo"]} to ${argv["target-owner"]}/${argv["target-repo"]}...`
);
const result = await issueSync.syncIssues({
sourceOwner: argv["source-owner"],
sourceRepo: argv["source-repo"],
targetOwner: argv["target-owner"],
targetRepo: argv["target-repo"],
state: argv.state,
labels: argv.labels,
syncComments: argv["sync-comments"],
});
if (result.created.length === 0) {
console.log("No new issues to synchronize.");
} else {
result.created.forEach((issue) => {
console.log(`✓ Created issue #${issue.number}: "${issue.title}"`);
});
}
if (result.skipped.length > 0) {
console.log(`\nSkipped ${result.skipped.length} issues (already exist in target repo)`);
}
console.log(
`\n✅ Synchronized ${result.created.length} issues from ${argv["source-owner"]}/${argv["source-repo"]} to ${argv["target-owner"]}/${argv["target-repo"]}`
);
} catch (error) {
console.error(error.message);
process.exit(1);
}
})();
}