Last active
June 25, 2020 11:35
-
-
Save Jarvvski/41d19d5817e6d4e98dd78fa6c5798d4c to your computer and use it in GitHub Desktop.
How to create a Github issue using the API within PHP
This file contains hidden or 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
| // $Token = personal access token for the account that will post the issue | |
| $headerValue = " Bearer " . $token; | |
| // Format the curl heaer (-H) with our auth code | |
| $header = array("Authorization:" . $headerValue); | |
| // Content for the issue | |
| $title = "I have a problem"; | |
| $body = "I broke it, how can i fix it?"; | |
| /* $label is an array of stirngs containing the labels we want to assign | |
| * If there isnt a label with the given name, github will generate it however | |
| */ we don't get to control the color of the label | |
| $label = array("Bug", "Feature"); | |
| // Format our data into an array with the following keys | |
| $data = array("title" => $title, "body" => $body, "labels" => array($label)); | |
| // prepare as json data | |
| $data_string = json_encode($data); | |
| // $repoOwner is the owern of the repository, usually the username | |
| // $repo is the name of the repository | |
| $url = sprintf("https://api.github.com/repos/%s/%s/issues", $repoOwner, $repo); | |
| // input the name of our application for github tracking | |
| $appName = 'My First API intergration"; | |
| //Send curl message | |
| $ch = curl_init(); | |
| curl_setopt($ch, CURLOPT_URL, $url ); | |
| curl_setopt($ch, CURLOPT_HTTPHEADER, $header); | |
| curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); | |
| curl_setopt($ch, CURLOPT_USERAGENT,$appName ); | |
| curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); | |
| // By setting the execution as a variable, we can get the returned | |
| // json data and extract it to outputs for viewing | |
| $response = curl_exec($ch); | |
| // close our connection | |
| curl_close($ch); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment