Beispiel #1
0
  def fetchAndMerge(self, args):
    repository = ['https://']
    if args.apiToken:
      repository.extend([args.apiToken, '@'])
    repository.append('github.com/')
    repositoryPrefix = ''.join(repository)
    repository.extend([args.repository, '.git'])
    repository = ''.join(repository)

    if args.pullRequest:
      pr_info = get_pr_info(args.repository, args.pullRequest, args.apiToken)
      commits = pr_info['commits']
      headLabel = pr_info['head']['label']
      baseLabel = pr_info['base']['label']
      branch_to_apply = pr_info['base']['ref']
      compare_info = get_compare_info(args.repository, headLabel, baseLabel, args.apiToken)
      reverse_compare_info = get_compare_info(args.repository, baseLabel, headLabel, args.apiToken)

      if not pr_info['merged'] and not pr_info['mergeable']:
        raise Exception('PR needs to be rebased to be mergeable')
      elif pr_info['merged']:
        raise Exception('PR has already been merged')
      merge_commit_sha = pr_info['merge_commit_sha']
    else:
      baseLabel = ':'.join([args.repository.split('/')[0], args.upstream])
      headLabel = ':'.join([args.originOwner, args.branchToBuild])
      branch_to_apply = args.upstream
      compare_info = get_compare_info(args.repository, headLabel, baseLabel, args.apiToken)
      reverse_compare_info = get_compare_info(args.repository, baseLabel, headLabel, args.apiToken)
      originRepo = repositoryPrefix + args.originOwner + '/' + args.repository.split('/')[1] + '.git'

    self.shell.call_and_check(['git', 'config', '--global', 'user.email', '*****@*****.**'], "Couldn't set email")
    self.shell.call_and_check(['git', 'config', '--global', 'user.name', 'docker-buildguy'], "Couldn't set email")
    self.shell.call_and_check(['git', 'clone', '--depth=' + str(int(reverse_compare_info['ahead_by']) + 10), '--branch', branch_to_apply, repository, 'build-dir/base' ], "Couldn't clone repo")
    with open(os.path.join(os.getcwd(), 'build-dir', 'diff.json'), 'w') as f:
      json.dump([ diffFile['filename'] for diffFile in compare_info['files'] ], f)
    self.shell.call_and_check(['cp', '-r', 'build-dir/base', 'build-dir/head' ], "Couldn't clone repo")
    os.chdir('build-dir/head')
    if args.pullRequest:
      self.shell.call_and_check(['git', 'fetch', '--depth=' + str(int(commits) + 10), 'origin', 'pull/' + str(args.pullRequest) + '/head:pullRequest'], "Couldn't fetch pr")
    else:
      self.shell.call_and_check(['git', 'fetch', '--depth=' + str(int(reverse_compare_info['ahead_by']) + 10), originRepo, args.branchToBuild + ':pullRequest'], "Couldn't fetch pr")
    self.shell.call_and_check(['git', 'merge', '--no-edit', '--no-ff', 'pullRequest'], "Couldn't merge pr")
    self.shell.call_and_check('git diff --name-only --relative origin/' + branch_to_apply + ' > checkdiff.out', 'Couldn\'t get diff files', shell= True)
Beispiel #2
0
    def fetchAndMerge(self, args):
        repository = ['https://']
        if args.apiToken:
            repository.extend([args.apiToken, '@'])
        repository.append('github.com/')
        repositoryPrefix = ''.join(repository)
        repository.extend([args.repository, '.git'])
        repository = ''.join(repository)

        if args.pullRequest:
            pr_info = get_pr_info(args.repository, args.pullRequest,
                                  args.apiToken)
            commits = pr_info['commits']
            headLabel = pr_info['head']['label']
            baseLabel = pr_info['base']['label']
            branch_to_apply = pr_info['base']['ref']
            compare_info = get_compare_info(args.repository, headLabel,
                                            baseLabel, args.apiToken)
            reverse_compare_info = get_compare_info(args.repository, baseLabel,
                                                    headLabel, args.apiToken)

            if not pr_info['merged'] and not pr_info['mergeable']:
                raise Exception('PR needs to be rebased to be mergeable')
            elif pr_info['merged']:
                raise Exception('PR has already been merged')
            merge_commit_sha = pr_info['merge_commit_sha']
        else:
            baseLabel = ':'.join(
                [args.repository.split('/')[0], args.upstream])
            headLabel = ':'.join([args.originOwner, args.branchToBuild])
            branch_to_apply = args.upstream
            compare_info = get_compare_info(args.repository, headLabel,
                                            baseLabel, args.apiToken)
            reverse_compare_info = get_compare_info(args.repository, baseLabel,
                                                    headLabel, args.apiToken)
            originRepo = repositoryPrefix + args.originOwner + '/' + args.repository.split(
                '/')[1] + '.git'

        self.shell.call_and_check([
            'git', 'config', '--global', 'user.email',
            '*****@*****.**'
        ], "Couldn't set email")
        self.shell.call_and_check(
            ['git', 'config', '--global', 'user.name', 'docker-buildguy'],
            "Couldn't set email")
        self.shell.call_and_check([
            'git', 'clone',
            '--depth=' + str(int(reverse_compare_info['ahead_by']) + 10),
            '--branch', branch_to_apply, repository, 'build-dir/base'
        ], "Couldn't clone repo")
        with open(os.path.join(os.getcwd(), 'build-dir', 'diff.json'),
                  'w') as f:
            json.dump(
                [diffFile['filename'] for diffFile in compare_info['files']],
                f)
        self.shell.call_and_check(
            ['cp', '-r', 'build-dir/base', 'build-dir/head'],
            "Couldn't clone repo")
        os.chdir('build-dir/head')
        if args.pullRequest:
            self.shell.call_and_check([
                'git', 'fetch', '--depth=' + str(int(commits) + 10), 'origin',
                'pull/' + str(args.pullRequest) + '/head:pullRequest'
            ], "Couldn't fetch pr")
        else:
            self.shell.call_and_check([
                'git', 'fetch',
                '--depth=' + str(int(reverse_compare_info['ahead_by']) + 10),
                originRepo, args.branchToBuild + ':pullRequest'
            ], "Couldn't fetch pr")
        self.shell.call_and_check(
            ['git', 'merge', '--no-edit', '--no-ff', 'pullRequest'],
            "Couldn't merge pr")
        self.shell.call_and_check('git diff --name-only --relative origin/' +
                                  branch_to_apply + ' > checkdiff.out',
                                  'Couldn\'t get diff files',
                                  shell=True)
Beispiel #3
0
    repositoryPrefix = 'https://'
    if api_token:
        repositoryPrefix += api_token
        repositoryPrefix += '@'
    repositoryPrefix += 'github.com/'
    repository = repositoryPrefix + args.repository
    repository += '.git'

    if args.pullRequest:
        pr_info = get_pr_info(args.repository, args.pullRequest, args.apiToken)
        commits = pr_info['commits']
        headLabel = pr_info['head']['label']
        baseLabel = pr_info['base']['label']
        branch_to_apply = pr_info['base']['ref']
        compare_info = get_compare_info(args.repository, headLabel, baseLabel,
                                        args.apiToken)
        reverse_compare_info = get_compare_info(args.repository, baseLabel,
                                                headLabel, args.apiToken)

        if not pr_info['merged'] and not pr_info['mergeable']:
            raise Exception('PR needs to be rebased to be mergeable')
        elif pr_info['merged']:
            raise Exception('PR has already been merged')
        merge_commit_sha = pr_info['merge_commit_sha']
    else:
        baseLabel = ':'.join([args.repository.split('/')[0], args.upstream])
        headLabel = ':'.join([args.originOwner, args.branchToBuild])
        branch_to_apply = args.upstream
        compare_info = get_compare_info(args.repository, headLabel, baseLabel,
                                        args.apiToken)
        reverse_compare_info = get_compare_info(args.repository, baseLabel,