Class: Senju::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/senju/repository.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ Repository

Returns a new instance of Repository.



18
19
20
21
22
# File 'lib/senju/repository.rb', line 18

def initialize(name, options)
  @name = options["repo"] || name
  @options = options
  @type = options["type"]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/senju/repository.rb', line 2

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



2
3
4
# File 'lib/senju/repository.rb', line 2

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



2
3
4
# File 'lib/senju/repository.rb', line 2

def type
  @type
end

Class Method Details

.allObject



4
5
6
7
8
# File 'lib/senju/repository.rb', line 4

def self.all
  Senju::Projects.data.map do |repository, config|
    new(repository, config)
  end
end

.find(name) ⇒ Object



14
15
16
# File 'lib/senju/repository.rb', line 14

def self.find(name)
  new(name, Senju::Projects[name])
end

.firstObject



10
11
12
# File 'lib/senju/repository.rb', line 10

def self.first
  all.first
end

Instance Method Details

#changes(no) ⇒ Object



67
68
69
70
71
72
73
74
75
76
# File 'lib/senju/repository.rb', line 67

def changes(no)
  case type
  when "github" then list = client.pull_request_files(name, no)
  when "gitlab" then list = client.merge_request_changes(name, no).changes
  end

  list.map do |raw|
    Senju::Change.new(raw, type)
  end
end

#clientObject



24
25
26
27
28
29
30
31
# File 'lib/senju/repository.rb', line 24

def client
  credential = Senju::Credential.find(type)
  case type
  when "github" then Senju::Github.new(credential)
  when "gitlab" then Senju::Gitlab.new(credential)
  when "trello" then Senju::Trello.new(credential)
  end
end

#comments(no) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'lib/senju/repository.rb', line 56

def comments(no)
  case type
  when "github" then list = client.issue_comments(name, no)
  when "gitlab" then list = client.issue_notes(name, no)
  end

  list.map do |raw|
    Senju::Comment.new(raw, type)
  end
end

#issue(no) ⇒ Object



45
46
47
# File 'lib/senju/repository.rb', line 45

def issue(no)
  Senju::Issue.new(client.issue(name, no), type)
end

#issuesObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/senju/repository.rb', line 33

def issues
  if type == "github"
    client.issues(name, labels: options["label"], assignee: options["assignee"]).map do |raw|
      Senju::Issue.new(raw, type)
    end
  else
    client.issues(name).map do |raw|
      Senju::Issue.new(raw, type)
    end
  end
end

#pull_request(no) ⇒ Object



49
50
51
52
53
54
# File 'lib/senju/repository.rb', line 49

def pull_request(no)
  case type
  when "github" then list = Senju::Issue.new(client.pull_request(name, no), type)
  when "gitlab" then list = Senju::Issue.new(client.merge_request(name, no), type)
  end
end

#pull_requestsObject



78
79
80
81
82
83
84
85
86
87
# File 'lib/senju/repository.rb', line 78

def pull_requests
  case type
  when "github" then list = client.pull_requests(name)
  when "gitlab" then list = client.merge_requests(name)
  end

  list.map do |raw|
    Senju::Issue.new(raw, type)
  end
end