forked from trustmaster/trac2github
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GET support for github_* functions, implement github_get_mileston…
…es, github_get_labels
- Loading branch information
Showing
1 changed file
with
23 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -306,19 +306,23 @@ | |
|
||
echo "Done whatever possible, sorry if not.\n"; | ||
|
||
function github_post($url, $json, $patch = false) { | ||
function github_req($url, $json, $patch = false, $post = true) { | ||
global $username, $password; | ||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); | ||
curl_setopt($ch, CURLOPT_URL, "https://api.github.com$url"); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | ||
curl_setopt($ch, CURLOPT_HEADER, false); | ||
curl_setopt($ch, CURLOPT_POST, true); | ||
curl_setopt($ch, CURLOPT_POST, $post); | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, $json); | ||
curl_setopt($ch, CURLOPT_USERAGENT, "trac2github for $project, [email protected]"); | ||
if ($patch) { | ||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); | ||
} else if ($post) { | ||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); | ||
} else { | ||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); | ||
} | ||
$ret = curl_exec($ch); | ||
if (!$ret) { | ||
|
@@ -331,31 +335,43 @@ function github_post($url, $json, $patch = false) { | |
function github_add_milestone($data) { | ||
global $project, $repo, $verbose; | ||
if ($verbose) print_r($data); | ||
return json_decode(github_post("/repos/$project/$repo/milestones", json_encode($data)), true); | ||
return json_decode(github_req("/repos/$project/$repo/milestones", json_encode($data)), true); | ||
} | ||
|
||
function github_add_label($data) { | ||
global $project, $repo, $verbose; | ||
if ($verbose) print_r($data); | ||
return json_decode(github_post("/repos/$project/$repo/labels", json_encode($data)), true); | ||
return json_decode(github_req("/repos/$project/$repo/labels", json_encode($data)), true); | ||
} | ||
|
||
function github_add_issue($data) { | ||
global $project, $repo, $verbose; | ||
if ($verbose) print_r($data); | ||
return json_decode(github_post("/repos/$project/$repo/issues", json_encode($data)), true); | ||
return json_decode(github_req("/repos/$project/$repo/issues", json_encode($data)), true); | ||
} | ||
|
||
function github_add_comment($issue, $body) { | ||
global $project, $repo, $verbose; | ||
if ($verbose) print_r($body); | ||
return json_decode(github_post("/repos/$project/$repo/issues/$issue/comments", json_encode(array('body' => $body))), true); | ||
return json_decode(github_req("/repos/$project/$repo/issues/$issue/comments", json_encode(array('body' => $body))), true); | ||
} | ||
|
||
function github_update_issue($issue, $data) { | ||
global $project, $repo, $verbose; | ||
if ($verbose) print_r($data); | ||
return json_decode(github_req("/repos/$project/$repo/issues/$issue", json_encode($data), true), true); | ||
} | ||
|
||
function github_get_milestones() { | ||
global $project, $repo, $verbose; | ||
if ($verbose) print_r($body); | ||
return json_decode(github_req("/repos/$project/$repo/milestones?per_page=100&state=all", false, false, false), true); | ||
} | ||
|
||
function github_get_labels() { | ||
global $project, $repo, $verbose; | ||
if ($verbose) print_r($body); | ||
return json_decode(github_post("/repos/$project/$repo/issues/$issue", json_encode($data), true), true); | ||
return json_decode(github_req("/repos/$project/$repo/labels?per_page=100", false, false, false), true); | ||
} | ||
|
||
function make_body($description) { | ||
|