Class: ChanControl

Inherits:
Object
  • Object
show all
Includes:
Cinch::Extensions::Authentication, Cinch::Plugin
Defined in:
lib/gitall/plugins/chancontrol.rb,
lib/gitall/plugins/git.rb

Overview

Note:

ChanControl Plugin

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.joined(channel) ⇒ Object

Note:

Ensures that the channel is joined or known of

Parameters:

  • channel (Channel)

    name of channel



117
118
119
# File 'lib/gitall/plugins/chancontrol.rb', line 117

def self.joined(channel)
  Channel(channel) ? true : false
end

Instance Method Details

#deFileHash

Load the config

Returns:

  • (Hash)

    load the current config



27
28
29
30
31
32
33
34
# File 'lib/gitall/plugins/chancontrol.rb', line 27

def deFile
  begin
    parsed = YAML.load(File.open(`echo ~/.gitall-rc.yml`.chomp, 'r'))
  rescue ArgumentError => e
    puts "Could not parse YAML: #{e.message}"
  end
  parsed
end

#getIssue(m, host, user, repo, issue) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gitall/plugins/git.rb', line 16

def getIssue(m, host, user, repo, issue)
  case host
  when 'gl'
    m.reply("https://gitlab.com/#{user}/#{repo}/issues/#{issue}")
  when 'gh'
    m.reply("https://github.com/#{user}/#{repo}/issue/#{issue}")
  when 'bb'
    m.reply("https://bitbucket.org/#{user}/#{repo}/issue/#{issue}")
  else
    m.user.notice("I don't know that git-service host")
  end
end

#getToken(m, length = nil) ⇒ String

Returns Token.

Parameters:

  • m (Message)

    message object

  • length (Integer) (defaults to: nil)

    token length

Returns:

  • (String)

    Token



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/gitall/plugins/chancontrol.rb', line 92

def getToken(m, length = nil)
  token = Strgen.generate do |c|
    if length.nil?
      c.length = 30
    else
      if length.to_i > 100
        c.length = 100
        m.reply 'Truncating to 100 characters due to spam concerns'
      else
        c.length = length
      end
    end
    c.alpha   = true
    c.numbers = true
    c.repeat  = false
    c.symbols = false
    c.exclude = %w[1 i I l L 0 o O]
  end
  m.user.send "Token: #{token}"
end

#listchans(m, project = nil) ⇒ Object

Parameters:

  • m (Object)

    Object



122
123
124
125
126
# File 'lib/gitall/plugins/chancontrol.rb', line 122

def listchans(m, project = nil)
  return unless authenticated? m
  project_hash = deFile['projects'][project]
  m.reply "Name: #{project} Host: #{project_hash['host'.to_sym]} Channels: #{project_hash['channels'.to_sym].join(" \xB7 ")}"
end

#padd(m, namespace = nil, host = nil, token = nil, channels = nil) ⇒ Object

of #channel,net

Parameters:

  • (Message)
  • namespace (String) (defaults to: nil)

    the Repository to watch

  • host (String) (defaults to: nil)

    the Git Service Website

  • token (String) (defaults to: nil)

    Secret Token @seealso #getToken

  • channels (ChannelList) (defaults to: nil)

    | separated list of channels in the format



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/gitall/plugins/chancontrol.rb', line 51

def padd(m, namespace = nil, host = nil, token = nil, channels = nil)
  if namespace.nil?
    m.reply 'Syntax: padd {OWNER/PROJECT} {github, gitlab, bitbucket}
              XXXXXXTOKEN #channel,network[|#channel2,network|#channel3,network2]'
    m.reply 'GitALL works best when using owner/repo webhooks, organization hooks have not been tested.'
  else
    return unless authenticated? m
    config = deFile
    if config[:projects].has_key? namespace
      m.user.send("#{m.user.nick}: #{namespace} already exists in the
config.")
    else
      config[:projects][namespace] = {
        host: host,
        token: token,
        channels: channels.split('|')
      }
      toFile(config)
      project = deFile().dig(:projects, namespace)
      m.user.send("Inputted: #{project}")
    end
    # @param [String] host
    def cap_host(host)
      case host.downcase
        when 'github'
          'GitHub.com'
        when 'gitlab'
          'GitLab.com'
        when 'bitbucket'
          'BitBucket.org'
      end
    end
    m.user.send("Remember to add the webhook to #{cap_host(host)} if you
haven't already.")
    info("Project added: #{project}")
  end
end

#toFile(msg) ⇒ Object

Write to the config

Parameters:

  • msg (Hash)

    the data to write



20
21
22
23
# File 'lib/gitall/plugins/chancontrol.rb', line 20

def toFile(msg)
  data = msg
  File.open(`echo ~/.gitall-rc.yml`.chomp, 'w') {|f| f.write(data.to_yaml) }
end