示例#1
0
    def createFromPR(cls, e):
        log = newCommitLogger(e['head']['sha'])
        sh = newLoggingShell(log)
        log(
            'Event',
            json.dumps(e,
                       ensure_ascii=False,
                       allow_nan=False,
                       indent=2,
                       sort_keys=True))
        commits = [c['commit'] for c in GET(e['commits_url'])]

        sh(f'git clone -b {e["base"]["ref"]} {env.CD_REPO_URL} .')

        if e["head"]["sha"] == sh(f'git merge-base HEAD {e["head"]["sha"]}'):
            log("Looks like this commit has already been merged.")
            return False

        try:
            if e['head']['repo']['fork']:
                sh(f'git pull --no-edit --no-ff {e["head"]["repo"]["ssh_url"]} {e["head"]["ref"]}'
                   )
            else:
                sh(f'git merge --no-edit --no-ff origin/{e["head"]["ref"]}')
        except:
            return False
        else:
            mergeHash = sh('git rev-parse HEAD')
            return cls(e['base']['sha'], e['head']['sha'], mergeHash, sh, log)
示例#2
0
    def pushToStaging(e):
        log = newCommitLogger(e['head'])
        sh = newLoggingShell(log)
        log('Event', json.dumps(e, ensure_ascii=False, allow_nan=False, indent=2, sort_keys=True))

        # fetch repo and checkout the commit that this event is for
        sh(f'git clone {env.CD_REPO_URL} .')
        sh(f'git checkout {e["head"]}')

        pass  # logic to deploy to staging, or call common function
示例#3
0
def quickCommand(e):
    commit = e['comment']['commit_id']
    command = e['comment']['body'].strip()[len('/quickcd'):].strip()
    log = newCommitLogger(commit)
    sh = newLoggingShell(log)
    log("Processing command: " + command)
    if command in commands:
        commands[command](commit, sh, log)
    else:
        log('Unknown command.')
        commands['help'](commit, sh, log)
示例#4
0
    def createFromMerge(cls, e):
        log = newCommitLogger(e['head'])
        sh = newLoggingShell(log)
        log(
            'Event',
            json.dumps(e,
                       ensure_ascii=False,
                       allow_nan=False,
                       indent=2,
                       sort_keys=True))

        sh(f'git clone {env.CD_REPO_URL} .')
        sh(f'git checkout {e["head"]}')

        return cls(e['before'], e['head'], e['head'], sh, log)
示例#5
0
    def deployAndTestPR(e):
        e = e['pull_request']
        log = newCommitLogger(e['head']['sha'])
        sh = newLoggingShell(log)
        log('Event', json.dumps(e, ensure_ascii=False, allow_nan=False, indent=2, sort_keys=True))
        commits = [c['commit'] for c in GET(e['commits_url'])]

        # fetch the repo and merge in changes from PR
        sh(f'git clone -b {e["base"]["ref"]} {env.CD_REPO_URL} .')
        try:
            if e['head']['repo']['fork']:
                sh(f'git pull --no-edit --no-ff {e["head"]["repo"]["ssh_url"]} {e["head"]["ref"]}')
            else:
                sh(f'git merge --no-edit --no-ff origin/{e["head"]["ref"]}')
        except:
            setCommitStatus(e["head"]["ref"], BuildStatus.failure, 'Merge failed', log.commentHTMLURL)

        pass  # logic to deploy to staging, or call common function