def get_snap_builds(snap_name): try: details = api.get_snap_info(snap_name, flask.session) # API call to make users without needed permissions refresh the session # Users needs package_upload_request permission to use this feature api.get_package_upload_macaroon(session=flask.session, snap_name=snap_name, channels=["edge"]) except ApiResponseErrorList as api_response_error_list: if api_response_error_list.status_code == 404: return flask.abort(404, "No snap named {}".format(snap_name)) else: return _handle_error_list(api_response_error_list.errors) except ApiError as api_error: return _handle_error(api_error) context = { "snap_id": details["snap_id"], "snap_name": details["snap_name"], "snap_title": details["title"], "snap_builds_enabled": False, "snap_builds": [], "total_builds": 0, } # Get built snap in launchpad with this store name github = GitHub(flask.session.get("github_auth_secret")) lp_snap = launchpad.get_snap_by_store_name(details["snap_name"]) if lp_snap: # Git repository without GitHub hostname context["github_repository"] = lp_snap["git_repository_url"][19:] github_owner, github_repo = context["github_repository"].split("/") context["yaml_file_exists"] = github.get_snapcraft_yaml_location( github_owner, github_repo) if not context["yaml_file_exists"]: flask.flash("This repository doesn't contain a snapcraft.yaml", "negative") context = get_builds(lp_snap, context, slice(0, BUILDS_PER_PAGE)) else: try: context["github_user"] = github.get_user() except Unauthorized: context["github_user"] = None if context["github_user"]: context["github_orgs"] = github.get_orgs() return flask.render_template("publisher/builds.html", **context)
def get_snap_builds(snap_name): try: details = publisher_api.get_snap_info(snap_name, flask.session) # API call to make users without needed permissions refresh the session # Users needs package_upload_request permission to use this feature publisher_api.get_package_upload_macaroon(session=flask.session, snap_name=snap_name, channels=["edge"]) except StoreApiResponseErrorList as api_response_error_list: if api_response_error_list.status_code == 404: return flask.abort(404, "No snap named {}".format(snap_name)) else: return _handle_error_list(api_response_error_list.errors) except (StoreApiError, ApiError) as api_error: return _handle_error(api_error) context = { "snap_id": details["snap_id"], "snap_name": details["snap_name"], "snap_title": details["title"], "snap_builds_enabled": False, "snap_builds": [], "total_builds": 0, } # Get built snap in launchpad with this store name lp_snap = launchpad.get_snap_by_store_name(details["snap_name"]) if lp_snap: # In this case we can use the GitHub user account or # the Snapcraft GitHub user to check the snapcraft.yaml github = GitHub( flask.session.get("github_auth_secret", GITHUB_SNAPCRAFT_USER_TOKEN)) # Git repository without GitHub hostname context["github_repository"] = lp_snap["git_repository_url"][19:] github_owner, github_repo = context["github_repository"].split("/") context["github_repository_exists"] = github.check_if_repo_exists( github_owner, github_repo) context["yaml_file_exists"] = github.get_snapcraft_yaml_location( github_owner, github_repo) context.update(get_builds(lp_snap, slice(0, BUILDS_PER_PAGE))) context["snap_builds_enabled"] = bool(context["snap_builds"]) else: github = GitHub(flask.session.get("github_auth_secret")) try: context["github_user"] = github.get_user() except Unauthorized: context["github_user"] = None if context["github_user"]: context["github_orgs"] = github.get_orgs() return flask.render_template("publisher/builds.html", **context)