Skip to content

Instantly share code, notes, and snippets.

@miyucy
Created October 18, 2016 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miyucy/c3e74dc36c305635501422e4e3c3ed38 to your computer and use it in GitHub Desktop.
Save miyucy/c3e74dc36c305635501422e4e3c3ed38 to your computer and use it in GitHub Desktop.
require 'restclient'
require 'json'
namespace :sentry do
class SentryReleaseAPI
def initialize(organization_slug: nil, project_slug: nil, api_key: nil)
@organization_slug = organization_slug || ENV['SENTRY_ORGANIZATION_SLUG']
@project_slug = project_slug || ENV['SENTRY_PROJECT_SLUG']
@api_key = api_key || ENV['SENTRY_API_KEY']
end
def ready?
@organization_slug && @project_slug && @api_key
end
def create(version, ref: nil, url: nil, date_started: nil, date_released: nil)
params = { version: version }
params[:ref] = ref if ref
params[:url] = url if url
params[:dateStarted] = date_started if date_started
params[:dateReleased] = date_released if date_released
url = %(https://#{@api_key}:@app.getsentry.com/api/0/projects/#{@organization_slug}/#{@project_slug}/releases/)
response = RestClient.post(url, params.to_json, content_type: 'application/json')
JSON.parse response
end
def upload(version, name, file)
url = %(https://#{@api_key}:@app.getsentry.com/api/0/projects/#{@organization_slug}/#{@project_slug}/releases/#{version}/files/)
response = RestClient.post(url, name: name, file: file)
JSON.parse response
end
end
task :release do
version = ENV['SOURCE_VERSION'] || `git rev-parse HEAD`
manifest = JSON.parse(File.binread(Dir[Rails.root.join('public/assets/.sprockets-manifest-*.json')].first))
release_api = SentryReleaseAPI.new
if release_api.ready?
release_api.create version
# release_api.upload version, URL String, IO Object
end
end
end
Rake::Task['assets:precompile'].enhance do
Rake::Task['sentry:release'].invoke
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment