├── Rakefile ├── lib └── capistrano │ ├── github │ ├── version.rb │ └── api.rb │ ├── github.rb │ └── tasks │ └── github.rake ├── Gemfile ├── .gitignore ├── capistrano-github.gemspec ├── LICENSE.txt └── README.md /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | -------------------------------------------------------------------------------- /lib/capistrano/github/version.rb: -------------------------------------------------------------------------------- 1 | module Capistrano 2 | module Github 3 | VERSION = "0.0.1" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in capistrano-github.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .yardoc 6 | Gemfile.lock 7 | InstalledFiles 8 | _yardoc 9 | coverage 10 | doc/ 11 | lib/bundler/man 12 | pkg 13 | rdoc 14 | spec/reports 15 | test/tmp 16 | test/version_tmp 17 | tmp 18 | -------------------------------------------------------------------------------- /lib/capistrano/github.rb: -------------------------------------------------------------------------------- 1 | load File.expand_path("../tasks/github.rake", __FILE__) 2 | 3 | require "capistrano/github/version" 4 | require "capistrano/github/api" 5 | 6 | module Capistrano 7 | module Github 8 | # Your code goes here... 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /capistrano-github.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'capistrano/github/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "capistrano-github" 8 | spec.version = Capistrano::Github::VERSION 9 | spec.authors = ["Kir Shatrov"] 10 | spec.email = ["shatrov@me.com"] 11 | spec.summary = %q{Integrates Capistrano with Github Deployments API} 12 | spec.homepage = "http://github.com/capistrano/github" 13 | spec.license = "MIT" 14 | 15 | spec.files = `git ls-files -z`.split("\x0") 16 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 17 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 18 | spec.require_paths = ["lib"] 19 | 20 | spec.add_dependency "capistrano", "~> 3.1" 21 | spec.add_dependency "octokit", ">= 3.0.0.pre" 22 | 23 | spec.add_development_dependency "bundler", "~> 1.5" 24 | spec.add_development_dependency "rake" 25 | end 26 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Kir Shatrov 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /lib/capistrano/tasks/github.rake: -------------------------------------------------------------------------------- 1 | namespace :github do 2 | 3 | desc 'Notify Github about new deployment' 4 | task :create_deployment do 5 | gh = Capistrano::Github::API.new(fetch(:repo_url), fetch(:github_access_token)) 6 | 7 | payload = { 8 | environment: fetch(:rails_env) 9 | } 10 | 11 | dep = gh.create_deployment(fetch(:branch), force: true, payload: payload) 12 | 13 | target = "http://#{primary(:app).hostname}" 14 | gh.create_deployment_status(dep.id, :pending, target) 15 | end 16 | 17 | desc 'List Github deployments' 18 | task :deployments do 19 | gh = Capistrano::Github::API.new(fetch(:repo_url), fetch(:github_access_token)) 20 | gh.deployments.each do |d| 21 | puts "Deployment: #{d.created_at} #{d.sha} by @#{d.creator_login} #{d.payload}" 22 | 23 | d.statuses.each do |s| 24 | puts "#{s.created_at} state: #{s.state}" 25 | end 26 | end 27 | end 28 | 29 | desc 'Finish Github deployment' 30 | task :finish_deployment do 31 | gh = Capistrano::Github::API.new(fetch(:repo_url)) 32 | 33 | target = primary(:app).hostname 34 | gh.create_deployment_status(dep.id, :failed, target) 35 | end 36 | 37 | end 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # This project is now [being maintained by @3scale](https://github.com/3scale/capistrano-github). 2 | 3 | *Old Readme:* 4 | 5 | # Capistrano::Github 6 | 7 | In January 2014 Github Team [announced Deployments API](http://developer.github.com/changes/2014-01-09-preview-the-new-deployments-api/) and you can use it with Capistrano 3. 8 | 9 | ## Installation 10 | 11 | Add this line to your application's Gemfile: 12 | 13 | gem 'capistrano-github', github: 'capistrano/github' 14 | gem 'octokit', github: 'octokit/octokit.rb', branch: 'deployments-preview' 15 | 16 | And then execute: 17 | 18 | $ bundle 19 | 20 | 21 | Require github tasks and set `github_access_token`: 22 | 23 | ```ruby 24 | # Capfile 25 | require 'capistrano/github' 26 | ``` 27 | 28 | ```ruby 29 | # deploy.rb 30 | set :github_access_token, '89c3be3d1f917b6ccf5e2c141dbc403f57bc140c' 31 | ``` 32 | 33 | You can get your personal GH token [here](https://github.com/settings/applications) 34 | 35 | ## Usage 36 | 37 | New deployment record will be created automatically on each `cap deploy` run. 38 | 39 | To see the list of deployments, execute 40 | 41 | ```bash 42 | cap production github:deployments 43 | ``` 44 | 45 | ## Contributing 46 | 47 | 1. Fork it ( http://github.com//capistrano-github/fork ) 48 | 2. Create your feature branch (`git checkout -b my-new-feature`) 49 | 3. Commit your changes (`git commit -am 'Add some feature'`) 50 | 4. Push to the branch (`git push origin my-new-feature`) 51 | 5. Create new Pull Request 52 | -------------------------------------------------------------------------------- /lib/capistrano/github/api.rb: -------------------------------------------------------------------------------- 1 | require 'octokit' 2 | 3 | module Capistrano 4 | module Github 5 | class API 6 | class Deployment 7 | attr_accessor :created_at, :sha, :creator_login, :payload, :statuses, :id 8 | 9 | class Status 10 | attr_accessor :created_at, :state 11 | end 12 | end 13 | 14 | REPO_FORMAT = /git@github.com:([\S]*)\/([\S]*).git/ 15 | 16 | attr_reader :client 17 | 18 | def initialize(full_repo_url, token) 19 | @client = Octokit::Client.new(access_token: token) 20 | @repo = parse_repo_url(repo_url) 21 | end 22 | 23 | def create_deployment(branch, options = {}) 24 | @client.create_deployment(@repo, branch, options) 25 | end 26 | 27 | def create_deployment_status(id, state, target) 28 | @client.create_deployment_status(deployment_url(id), state) 29 | end 30 | 31 | def deployments 32 | @client.deployments(@repo).map do |d| 33 | Deployment.new.tap do |dep| 34 | dep.created_at = d.created_at 35 | dep.sha = d.sha 36 | dep.creator_login = d.creator.login 37 | dep.payload = d.payload 38 | dep.id = d.id 39 | 40 | dep.statuses = deployment_statuses(d.id) 41 | end 42 | end 43 | end 44 | 45 | private 46 | 47 | def deployment_statuses(id) 48 | @client.deployment_statuses(deployment_url(id)) 49 | end 50 | 51 | def deployment_url(id) 52 | "repos/#{@repo}/deployments/#{id}" 53 | end 54 | 55 | def parse_repo_url(url) 56 | repo_match = url.match(REPO_FORMAT) 57 | "#{repo_match[1]}/#{repo_match[2]}" 58 | end 59 | end 60 | end 61 | end 62 | --------------------------------------------------------------------------------