bouiboui\Tissue\GithubIssue::commit PHP Method

commit() public method

Actually creates the issue on Github, returns an array with the issue's number and URL.
public commit ( $yourUsername, $yourPassword, $targetRepoAuthor, $targetRepoName ) : array
$yourUsername
$yourPassword
$targetRepoAuthor
$targetRepoName
return array
    public function commit($yourUsername, $yourPassword, $targetRepoAuthor, $targetRepoName)
    {
        $client = new GithubClient();
        $client->authenticate($yourUsername, $yourPassword, GithubClient::AUTH_HTTP_PASSWORD);
        /** @var Search $searchApi */
        $searchApi = $client->api('search');
        /** @var Issue $issueApi */
        $issueApi = $client->api('issue');
        // Check existing issues to avoid duplicates
        $duplicates = $searchApi->issues($this->title . ' in:title state:open label:bug repo:' . $targetRepoAuthor . '/' . $targetRepoName);
        if ((int) $duplicates['total_count'] > 0) {
            return ['duplicate' => true];
        }
        // Create the issue and fetch the issue's info
        $issueInfo = $issueApi->create($targetRepoAuthor, $targetRepoName, ['title' => $this->title, 'body' => $this->body]);
        if (!array_key_exists('number', $issueInfo) || !array_key_exists('url', $issueInfo)) {
            throw new ErrorException('Missing Github issue info parameter');
        }
        // Apply the "Bug" label
        $issueApi->labels()->add($targetRepoAuthor, $targetRepoName, $issueInfo['number'], 'bug');
        $this->number = $issueInfo['number'];
        $this->url = $issueInfo['url'];
        return ['duplicate' => false, 'number' => $this->number, 'url' => $this->url];
    }

Usage Example

Esempio n. 1
0
 /**
  * Create an issue from the sent request
  * @param null $message
  * @param null $code
  * @param null $severity
  * @param null $path
  * @param null $lineno
  * @param null $trace
  * @return array
  * @throws ErrorException
  * @throws InvalidArgumentException
  * @throws MissingArgumentException
  * @throws ParseException
  */
 public static function create($message = null, $code = null, $severity = null, $path = null, $lineno = null, $trace = null)
 {
     static::loadConfig();
     if (null === array_unique([$message, $code, $severity, $path, $lineno, $trace])) {
         throw new ErrorException('At least one parameter must be set.');
     }
     $issue = new GithubIssue($message, $code, $severity, $path, $lineno, $trace);
     return $issue->commit(static::$config['you']['username'], static::$config['you']['password'], static::$config['repo']['author'], static::$config['repo']['name']);
 }