app/helpers/sessions_helper.rb
# Return true iff the current user can edit the given url.
#
# The GitHub API documentation here:
# https://developer.github.com/v3/repos/collaborators/
# #review-a-users-permission-level
# says that if you retrieve:
# GET /repos/:owner/:repo/collaborators/:username/permission
# If "permission" is write or admin then that user can modify it.
# HOWEVER, the use of that API is not allowed with an OAuth token, only
# normal access token. So while that *looks* useful, it doesn't work for our
# situation.
#
# As of 2020-04-16, retrieving a repo using GitHub repos API (using
# https://api.github.com/:owner/:repo) with a users OAuth token will include
# a field `permissions`.  We consider a user with `push` permissions an
# editor and check for that.
Return true iff the current user can edit the given url.


Return true iff the current user can edit the given url .
def github_user_can_push?(url, client = Octokit::Client)
    github_path = get_github_path(url)
    return false if github_path.nil?
    github = client.new access_token: session[:user_token]
    begin
      github.repo(github_path).permissions.push
    rescue Octokit::NotFound
      false
    end
  end
def github_user_can_push? ( url , client = Octokit :: Client ) github_path = get_github_path ( url ) return false if github_path . nil? github = client . new access_token : session [ :user_token ] begin github . repo ( github_path ) . permissions . push rescue Octokit :: NotFound false end end
Return true iff the current user can edit the given url.
Return true iff the current user can edit the given url .
# If you suddenly get a lot of 503's most likely github has changed # its API, make this a generic rescue # Disable rubocop - Style/RescueStandardError if that is needed
url
<not_specific>
client
<not_specific>