def get_ref_and_sha(payload):
    action = payload.get('action')

    if action is None:
        # See `tests.func_fixtures.PUSH_HOOK_CALL_DATA` for payload
        ref = payload.get('ref')  # ref looks like "refs/heads/master"
        if not ref or not ref.startswith('refs/heads/'):
            return None
        prefix_length = len('refs/heads/')
        ref = ref[prefix_length:]
        sha = payload.get('head_commit', {}).get('id')
        if not sha:
            return None
        return ref, sha

    elif action in ('opened', 'synchronize'):
        # See `tests.func_fixtures.PULL_REQUEST_HOOK_CALL_DATA` for payload
        gh_pull = github3.pulls.PullRequest(payload.get('pull_request', {}))
        try:
            return gh_pull.head.ref, gh_pull.head.sha
        except:
            return None
    else:
        return None
dataset/ETHPy150Open aromanovich/kozmic-ci/kozmic/builds/views.py/get_ref_and_sha/original