Class: Puppetfactory::Plugins::Github
- Inherits:
-
Puppetfactory::Plugins
- Object
- Puppetfactory::Plugins
- Puppetfactory::Plugins::Github
- Defined in:
- lib/puppetfactory/plugins/github.rb
Instance Attribute Summary
Attributes inherited from Puppetfactory::Plugins
Instance Method Summary collapse
- #create(username, password) ⇒ Object
- #delete(username) ⇒ Object
-
#initialize(options) ⇒ Github
constructor
A new instance of Github.
- #userinfo(username, extended = false) ⇒ Object
Constructor Details
#initialize(options) ⇒ Github
Returns a new instance of Github.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/puppetfactory/plugins/github.rb', line 6 def initialize() super() @gitserver = [:gitserver] @gituser = [:gituser] @controlrepo = [:controlrepo] @repomodel = [:repomodel] @githubtoken = [:githubtoken] # chomp so we can support repo names with or without the .git @controlrepo.chomp!('.git') if @githubtoken @client = Octokit::Client.new(:access_token => @githubtoken) @client.user.login else @client = Octokit::Client.new() end end |
Instance Method Details
#create(username, password) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/puppetfactory/plugins/github.rb', line 26 def create(username, password) # can only do anything on our own repo, and only if we're authorized! return true unless @githubtoken and @repomodel == :single begin # can only do anything on our own repo! repo = "#{@gituser}/#{@controlrepo}" sha = @client.branches(repo).select { |branch| branch[:name] == 'production' }.first[:commit][:sha] @client.create_ref(repo, "heads/#{username}", sha) $logger.info "Created Github user branch for #{username}" @client.add_collaborator(repo, username) $logger.info "Added #{username} as a collaborator to #{repo}." rescue => e $logger.error "Error creating Github user branch for #{username}" $logger.error e. return false end true end |
#delete(username) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/puppetfactory/plugins/github.rb', line 49 def delete(username) # can only do anything on our own repo, and only if we're authorized! return true unless @githubtoken and @repomodel == :single begin @client.delete_branch("#{@gituser}/#{@controlrepo}", username) $logger.info "Deleted Github user branch for #{username}" @client.remove_collaborator(repo, username) $logger.info "Removed #{username} as a collaborator on #{repo}." rescue => e $logger.error "Error deleting Github user branch for #{username}" $logger.error e. return false end true end |
#userinfo(username, extended = false) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/puppetfactory/plugins/github.rb', line 69 def userinfo(username, extended = false) if @repomodel == :single repo = "#{@gituser}/#{@controlrepo}" url = "#{@gitserver}/#{@gituser}/#{@controlrepo}/tree/#{username}" else repo = "#{@username}/#{@controlrepo}" url = "#{@gitserver}/#{username}/#{@controlrepo}" end userinfo = { :username => username, :controlrepo => url, } userinfo[:latestcommit] = latest_commit(repo, username) if extended userinfo end |