

@must_not_be_registration
@must_have_addon(SHORT_NAME, 'user')
@must_have_addon(SHORT_NAME, 'node')
@must_be_addon_authorizer(SHORT_NAME)
@must_have_permission('write')
def github_set_config(auth, **kwargs):
    node_settings = kwargs.get('node_addon', None)
    node = kwargs.get('node', None)
    user_settings = kwargs.get('user_addon', None)
    try:
        if (not node):
            node = node_settings.owner
        if (not user_settings):
            user_settings = node_settings.user_settings
    except AttributeError:
        raise HTTPError(http.BAD_REQUEST)
    github_user_name = request.json.get('github_user', '')
    github_repo_name = request.json.get('github_repo', '')
    if ((not github_user_name) or (not github_repo_name)):
        raise HTTPError(http.BAD_REQUEST)
    connection = GitHubClient(external_account=node_settings.external_account)
    repo = connection.repo(github_user_name, github_repo_name)
    if (repo is None):
        if user_settings:
            message = 'Cannot access repo. Either the repo does not exist or your account does not have permission to view it.'
        else:
            message = 'Cannot access repo.'
        return ({
            'message': message,
        }, http.BAD_REQUEST)
    changed = ((github_user_name != node_settings.user) or (github_repo_name != node_settings.repo))
    if changed:
        node_settings.delete_hook()
        node_settings.user = github_user_name
        node_settings.repo = github_repo_name
        user_settings.add_log(action='github_repo_linked', params={
            'project': node.parent_id,
            'node': node._id,
            'github': {
                'user': github_user_name,
                'repo': github_repo_name,
            },
        }, auth=auth)
        if (node_settings.user and node_settings.repo):
            node_settings.add_hook(save=False)
        node_settings.save()
    return {
        
    }

dataset/ETHPy150Open CenterForOpenScience/osf.io/website/addons/github/views.py github_set_config/VarMisuse@286/474 `node`->`user_settings`