void print_issue(struct json_object* issue, char* token, char* repo) { struct json_object* comments; struct json_object* comment; char* comment_user; char* comment_body; int len; int i; char* title = jsonh_get_string(issue, "title"); char* body = jsonh_get_string(issue, "body"); char* user = jsonh_get_string(issue, "user.login"); char* assignee = jsonh_get_string(issue, "assignee.login"); char* milestone = jsonh_get_string(issue, "milestone.title"); char* url = jsonh_get_string(issue, "pull_request.html_url"); char* status = jsonh_get_string(issue, "state"); char* type = url == NULL ? "Issue" : "Pull Request"; char* issue_id = jsonh_get_string(issue, "number"); int comment_count = jsonh_get_int(issue, "comments"); printf("%s: %s\t\t%s: %s\t\t%s: %s\t\t%s: %s\n", bold("Title"), title, bold("Opened by"), user, bold("Assigned to"), assignee, bold("Milestone"), milestone); printf("%s: %s\t\t%s: %s\t\t%s: %s\n", bold("URL"), url, bold("Type"), type, bold("Status"), status); printf("%s: %s\n\n", bold("Body"), body); if (comment_count > 0) { comments = github_get_comments(repo, issue_id, token); len = json_object_array_length(comments); for (i = 0; i < len; i++) { comment = json_object_array_get_idx(comments, i); comment_user = jsonh_get_string(comment, "user.login"); comment_body = jsonh_get_string(comment, "body"); printf("%s:\t%s\n\n", bold(comment_user), comment_body); } } }
int main(int argc, char *argv[]) { int c; extern char* optarg; struct json_object* response; char* title = NULL; char* body = NULL; char* token = config_get_token(); char* repo = repo_get_repo(); char* base = "master"; char* head = repo_get_branch(); struct json_object* pr = json_object_new_object(); if (token == NULL || repo == NULL) return 1; while ((c = getopt(argc, argv, "t:m:b:h:")) != EOF) { switch (c) { case 't': title = optarg; break; case 'm': body = optarg; break; case 'b': base = optarg; break; case 'h': head = optarg; break; } } if (title == NULL || body == NULL) { fprintf(stderr, "Usage: git pr -m \"pr body\" -t \"pr title\" [-b base] [-h head]\n"); return 1; } json_object_object_add(pr, "title", json_object_new_string(title)); json_object_object_add(pr, "body", json_object_new_string(body)); json_object_object_add(pr, "base", json_object_new_string(base)); json_object_object_add(pr, "head", json_object_new_string(head)); response = github_create_pr(repo, pr, token); if (response) { printf("Created pr #%s\n", jsonh_get_string(response, "number")); return 0; } return 1; }
int main(int argc, char *argv[]) { int c; extern char* optarg; struct json_object* response; char* title = NULL; char* body = NULL; char* token = config_get_token(); char* repo = repo_get_repo(); struct json_object* issue = json_object_new_object(); if (token == NULL || repo == NULL) return 1; while ((c = getopt(argc, argv, "t:m:")) != EOF) { switch (c) { case 't': title = optarg; break; case 'm': body = optarg; break; } } if (title == NULL || body == NULL) { fprintf(stderr, "Usage: git issue -m \"issue body\" -t \"issue title\"\n"); return 1; } json_object_object_add(issue, "title", json_object_new_string(title)); json_object_object_add(issue, "body", json_object_new_string(body)); response = github_create_issue(repo, issue, token); if (response) { printf("Created issue #%s\n", jsonh_get_string(response, "number")); return 0; } return 1; }