Skip to content

Commit 56d9d60

Browse files
Add option --labels to the newpr command
1 parent 49344bb commit 56d9d60

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

docs/gh.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ Define the PR title.
4848
.IP "--assignees=<value1>,<value2>,<valueN>"
4949
Define the PR assignees.
5050

51+
.IP "--labels=<value1>,<value2>,valueN>"
52+
Define the PR labels.
53+
5154
.SH FILES
5255
.TP
5356
.I

src/gh.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ static void set_destination_and_source(struct Prompt *p, char *dest_src);
1818
static void set_template(struct Prompt *p, char *template);
1919
static void set_title(struct Prompt *p, char *title);
2020
static void set_assignees(struct Prompt *p, char *assignees);
21+
static void set_labels(struct Prompt *p, char *labels);
2122
static void assure_query_param_support(struct Prompt *p);
2223
static void warn_missing_branches(struct Prompt *p);
2324

@@ -213,6 +214,8 @@ static void handle_newpr_options(struct Prompt *p) {
213214
set_title(p, p->opts[i].value);
214215
} else if (strcmp(p->opts[i].key, "--assignees") == 0) {
215216
set_assignees(p, p->opts[i].value);
217+
} else if (strcmp(p->opts[i].key, "--labels") == 0) {
218+
set_labels(p, p->opts[i].value);
216219
}
217220
}
218221

@@ -256,6 +259,13 @@ static void set_assignees(struct Prompt *p, char *assignees) {
256259
strcat(p->instruction, assignees);
257260
}
258261

262+
static void set_labels(struct Prompt *p, char *labels) {
263+
assure_query_param_support(p);
264+
265+
strcat(p->instruction, "&labels=");
266+
strcat(p->instruction, labels);
267+
}
268+
259269
static void assure_query_param_support(struct Prompt *p) {
260270
if (strstr(p->instruction, "?expand=1") != NULL) return;
261271

src/gh.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#define MAX_STR_SIZE 255
77

88
#define INVALID_CMD -1
9-
#define MAX_CMD_OPTS 4
9+
#define MAX_CMD_OPTS 5
1010
#define DEFAULT_CMD 1
1111
#define REPO_CMD 1
1212
#define HELP_CMD 2

tests/gh_tests.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ static void test_newpr_instruction_generation(void **state) {
190190
strcpy(newpr_with_options.opts[1].value, "feature.md");
191191
strcpy(newpr_with_options.opts[2].key, "--assignees");
192192
strcpy(newpr_with_options.opts[2].value, "gustavothecoder");
193+
strcpy(newpr_with_options.opts[3].key, "--labels");
194+
strcpy(newpr_with_options.opts[3].value, "feature,minor");
193195

194196
struct Prompt newpr_with_only_template_option = { NEWPR_CMD };
195197
strcpy(newpr_with_only_template_option.opts[0].key, "--template");
@@ -216,7 +218,7 @@ static void test_newpr_instruction_generation(void **state) {
216218
assert_string_equal(
217219
newpr_with_options.instruction,
218220
"firefox --new-tab 'github.com/fakeuser/fakerepo/compare/main...task/jc-123" \
219-
"?expand=1&template=feature.md&assignees=gustavothecoder'"
221+
"?expand=1&template=feature.md&assignees=gustavothecoder&labels=feature,minor'"
220222
);
221223
assert_string_equal(
222224
newpr_with_only_template_option.instruction,

0 commit comments

Comments
 (0)