imports project file from github.

@param string $repository
@param string $branch
@param string $file

@return array
177221
public function import($repository, $branch = null, $file = null)
    {
        return $this->request(sprintf('github/%s?branch=%s&file=%s', $this->transform($repository), $branch, $file), 'POST');
    }
1049587
public function branches($project_id, array $parameters = [])
    {
        $resolver = $this->createOptionsResolver();
        $resolver->setDefined('search')
            ->setAllowedTypes('search', 'string');

        return $this->get($this->getProjectPath($project_id, 'repository/branches'), $resolver->resolve($parameters));
    }
664870
protected function doGitInit(GitWorkingCopy $workingCopy, $url, $branch)
    {
        $workingCopy->init();
        $workingCopy->remote('add', 'origin', $url);

        try {

            $this->output->writeln("Attempting to fetch <path>origin/{$branch}</path>", OutputInterface::VERBOSITY_VERBOSE);

            $workingCopy
                ->fetch('origin', $branch)
                ->checkout('-f', $branch);

        } catch (GitException $exception) {

            $this->output->writeln("Fetch failed, creating new branch instead", OutputInterface::VERBOSITY_VERBOSE);

            $workingCopy
                ->checkout('--orphan', $branch)
                ->run(['commit', '--allow-empty', '-m', "Branch created by steak"])
                ->push('-u', 'origin', $branch);

        }

        return $workingCopy->clearOutput();
    }
1101084
public function main()
    {
        if (null === $this->getRepository()) {
            throw new BuildException('"repository" is required parameter');
        }
        if (null === $this->getBranchname()) {
            throw new BuildException('"branchname" is required parameter');
        }

        // if we are moving branch, we need to know new name
        if ($this->isMove() || $this->isForceMove()) {
            if (null === $this->getNewBranch()) {
                throw new BuildException('"newbranch" is required parameter');
            }
        }

        $client = $this->getGitClient(false, $this->getRepository());

        $command = $client->getCommand('branch');

        if (version_compare($client->getGitVersion(), '2.15.0', '<')) {
            $command->setOption('set-upstream', $this->isSetUpstream());
        } elseif ($this->isSetUpstreamTo()) {
            $command->setOption('set-upstream-to', $this->getSetUpstreamTo());
        }

        $command
            ->setOption('no-track', $this->isNoTrack())
            ->setOption('force', $this->isForce());
        if ($this->isNoTrack() == false) {
            $command->setOption('track', $this->getTrack());
        }

        // check extra options (delete, move)
        foreach ($this->extraOptions as $option => $flag) {
            if ($flag) {
                $command->setOption($option, true);
            }
        }

        $command->addArgument($this->getBranchname());

        if (null !== $this->getStartPoint()) {
            $command->addArgument($this->getStartPoint());
        }

        if (null !== $this->getNewBranch()) {
            $command->addArgument($this->getNewBranch());
        }

        $this->log('git-branch command: ' . $command->createCommandString(), Project::MSG_INFO);

        try {
            $output = $command->execute();
        } catch (Exception $e) {
            throw new BuildException(
                'Task execution failed with git command "' . $command->createCommandString() . '""',
                $e
            );
        }

        $this->log(
            sprintf('git-branch: branch "%s" repository', $this->getRepository()),
            Project::MSG_INFO
        );
        $this->log('git-branch output: ' . str_replace('\'', '', trim($output)), Project::MSG_INFO);
    }
306621
public function add_endpoints( $git, $endpoint ) {
		switch ( self::$method ) {
			case 'meta':
			case 'translation':
			case 'branches':
				break;
			case 'file':
			case 'readme':
				$endpoint = add_query_arg( 'at', $git->type->branch, $endpoint );
				break;
			case 'changes':
				$endpoint = add_query_arg(
					[
						'at'  => $git->type->branch,
						'raw' => '',
					],
					$endpoint
				);
				break;
			case 'tags':
			case 'download_link':
				/*
				 * Add a prefix query argument to create a subdirectory with the same name
				 * as the repo, e.g. 'my-repo' becomes 'my-repo/'
				 * Required for using stash-archive.
				 */
				$defaults = [
					'prefix' => $git->type->slug . '/',
					'at'     => $git->type->branch,
					'format' => 'zip',
				];
				$endpoint = add_query_arg( $defaults, $endpoint );
				if ( ! empty( $git->type->tags ) ) {
					$endpoint = urldecode( add_query_arg( 'at', $git->type->newest_tag, $endpoint ) );
				}
				break;
			default:
				break;
		}

		return $endpoint;
	}
126307
def load_branches
      Hash[@grit_repo.branches.map { |b| [b.name, b.commit.id] }]
    end
668427
protected function githubCommitRequest(Project $project, array $payload)
    {
        // Github sends a payload when you close a pull request with a
        // non-existent commit. We don't want this.
        if (array_key_exists('after', $payload) && $payload['after'] === '0000000000000000000000000000000000000000') {
            return array('status' => 'ignored');
        }

        if (isset($payload['commits']) && is_array($payload['commits'])) {
            // If we have a list of commits, then add them all as builds to be tested:

            $results = array();
            $status = 'failed';
            foreach ($payload['commits'] as $commit) {
                if (!$commit['distinct']) {
                    $results[$commit['id']] = array('status' => 'ignored');
                    continue;
                }

                try {
                    $branch = str_replace('refs/heads/', '', $payload['ref']);
                    $committer = $commit['committer']['email'];
                    $results[$commit['id']] = $this->createBuild(
                        $project,
                        $commit['id'],
                        $branch,
                        $committer,
                        $commit['message']
                    );
                    $status = 'ok';
                } catch (Exception $ex) {
                    $results[$commit['id']] = array('status' => 'failed', 'error' => $ex->getMessage());
                }
            }
            return array('status' => $status, 'commits' => $results);
        }

        if (substr($payload['ref'], 0, 10) == 'refs/tags/') {
            // If we don't, but we're dealing with a tag, add that instead:
            $branch = str_replace('refs/tags/', 'Tag: ', $payload['ref']);
            $committer = $payload['pusher']['email'];
            $message = $payload['head_commit']['message'];
            return $this->createBuild($project, $payload['after'], $branch, $committer, $message);
        }

        return array('status' => 'ignored', 'message' => 'Unusable payload.');
    }
216238
public function gitHubInitRepo(InputInterface $input, OutputInterface $output)
    {
        $this->output = $output;
        $this->runGitInit();
        $this->runGitAdd();
        $this->runGitCommit();
        $this->runGitCreateRepo();
        $this->runGitRemoteAddOrigin($this->getRepoURL($input,$output));
        $this->runGitPull();
        $this->runGitPush();
    }
1248744
public List<GitlabCommit> getAllCommits(Serializable projectId, String branchOrTag) throws IOException {
        return getAllCommits(projectId, null, branchOrTag);
    }
611277
public function addBranch(Branch $branch)
    {
        if ($this->currentBranch) {
            $branch->setParentBranch($this->currentBranch);
            $this->currentBranch = $branch;
        } else {
            $this->currentBranch = $branch;
        }

        $branch->setUniqueId($this->uniqueId);
        $branch->setLevel($this->level);

        ++$this->level;
        ++$this->uniqueId;

        if (Branch::TYPE_ROOT == $branch->getType()) {
            $this->setRootBranch($branch);
        }
    }
328341
public function githubCreateRepo(InputInterface $input, OutputInterface $output)
    {
        $this->api->setCredentials($this->getCredentials($output));
        $name = $this->repoName($input);
        try {
            $this->api->createRepo($name,$this->repoDescription($input));
        } catch (ServerException $se) {
            //TODO
            $output->writeln('<error>Server exception thrown</error>');
            die();
        } catch (ClientException $ce) {
            $this->showError( $ce , $output );
        }
        $output->writeln('<info>Repository ' . $name . ' created</info>');
    }
1118239
public function getBranches($repository)
    {
        $response = $this->sendRequest(sprintf('repos/%s/branches', $repository));

        $result = [];

        if ($response->getStatusCode() == 200) {
            $responseJson = $response->json();
            $commits = [];

            foreach ($responseJson['commits'] as $item) {
                $commit = new Commit();
                Commit::hydrate($item, $commit);

                $commits[$commit->getId()] = $commit;
            }

            foreach ($responseJson['branches'] as $item) {
                $branch = new Branch();
                $item['commit'] = $commits[$item['commit_id']];
                Branch::hydrate($item, $branch);

                $result[] = $branch;
            }
        }

        return $result;
    }
782105
private function resolveBranch($user, $repo, $branch)
    {
        $api = $this->client->api('git_data')->references();
        $params = [$user, $repo, sprintf('heads/%s', $branch)];

        $data = $this->callGitHub([$api, 'show'], $params);
        return $data['object']['sha'] ?? null;
    }
264881
public function publishRelease($repository, $label = 'none', $origin = '') {
      if (!in_array($label, ['rc', 'beta', 'alpha', 'none'])) {
         throw new \InvalidArgumentException('Release label, can be rc, beta, alpha or none');
      }
      $this->options['label'] = $label;

      // changelog generation
      $result = $this->makeChangelog($repository);
      if (null !== $result && $result->wasCancelled()) {
         $this->say($result->getMessage());
         return;
      }

      $newVersion = $this->newVersion;
      $releaseBranch = 'release/' . $newVersion;

      // git-flow start
      $this->taskGitStack()->checkout('-b ' . $releaseBranch)->run();

      // Continue the git flow
      $filename = 'CHANGELOG.md';
      $commitMessage = 'docs: updated project files for new release.';
      $composerFile = 'composer.json';
      $this->composerUpdate($composerFile);
      $this->taskGitStack()->add($filename)->add($composerFile)
         ->commit($commitMessage, '--no-gpg-sign')
         ->checkout('-b robo-master upstream/master')
         ->merge($releaseBranch)->tag($newVersion)
         ->checkout('-b robo-develop upstream/develop')->merge($releaseBranch)
         ->run();

      // finish git-flow with delete release branch
      $this->taskGitStack()->exec('branch -D ' . $releaseBranch)->run();

      // make changelog for gh-pages
      $this->taskGitStack()->checkout('-b robo-gh-pages upstream/gh-pages')->checkout('robo-develop ' . $filename)->run();
      $this->_exec('mv -f ' . $filename. ' _includes/' . $filename);
      $this->taskGitStack()->add('_includes/' .$filename)->commit($commitMessage, '--no-gpg-sign')->run();

      // publish the changes
      if ($origin) {
         $this->taskGitStack()
            ->push($origin, 'robo-gh-pages:gh-pages')
            ->push($origin, 'robo-develop:develop')
            ->push($origin, 'robo-master:master')
            ->push($origin, $newVersion)
            ->run();
      }
   }
297041
public function main()
    {
        if (null === $this->getRepository()) {
            throw new BuildException('"repository" is required parameter');
        }
        if (null === $this->getBranchname()) {
            throw new BuildException('"branchname" is required parameter');
        }

        $client = $this->getGitClient(false, $this->getRepository());
        $command = $client->getCommand('checkout');
        $command
            ->setOption('no-track', $this->isNoTrack())
            ->setOption('q', $this->isQuiet())
            ->setOption('force', $this->isForce())
            ->setOption('b', $this->isCreate())
            ->setOption('B', $this->isForceCreate())
            ->setOption('m', $this->isMerge());
        if ($this->isNoTrack()) {
            $command->setOption('track', $this->isTrack());
        }

        $command->addArgument($this->getBranchname());

        if (null !== $this->getStartPoint()) {
            $command->addArgument($this->getStartPoint());
        }

        $this->log('git-checkout command: ' . $command->createCommandString(), Project::MSG_INFO);

        try {
            $output = $command->execute();
        } catch (Exception $e) {
            throw new BuildException('Task execution failed.', $e);
        }

        $this->log(
            sprintf('git-checkout: checkout "%s" repository', $this->getRepository()),
            Project::MSG_INFO
        );
        $this->log('git-checkout output: ' . str_replace('\'', '', trim($output)), Project::MSG_INFO);
    }
508673
public function add_endpoints( $git, $endpoint ) {
		switch ( $git::$method ) {
			case 'projects':
				$endpoint = add_query_arg( 'per_page', '100', $endpoint );
				break;
			case 'meta':
			case 'tags':
			case 'branches':
			case 'download_link':
				break;
			case 'file':
			case 'changes':
			case 'readme':
				$endpoint = add_query_arg( 'ref', $git->type->branch, $endpoint );
				break;
			case 'translation':
				$endpoint = add_query_arg( 'ref', 'master', $endpoint );
				break;
			case 'release_asset':
				$endpoint = add_query_arg( 'job', $git->type->ci_job, $endpoint );
				break;
			default:
				break;
		}

		$endpoint = $this->add_access_token_endpoint( $git, $endpoint );

		/*
		 * If GitLab CE/Enterprise return this endpoint.
		 */
		if ( ! empty( $git->type->enterprise_api ) ) {
			return $git->type->enterprise_api . $endpoint;
		}

		return $endpoint;
	}
158848
private function addRelations(Repository $repo, MutableBag $relationQueue, Bag $importDatum, MutableBag $relationFields)
    {
        $classMeta = $repo->getClassMetadata();
        foreach ($relationFields as $fieldName) {
            $relationName = $classMeta->getBoltName() . '/' . $importDatum->get('slug');

            $existing = (array) $relationQueue->get($relationName);
            $relatedEntities = $importDatum->get($fieldName);

            if ($relatedEntities) {
                $relationQueue->set($relationName, array_merge($relatedEntities->toArray(), $existing));
            }
        }
    }