Class: Blend::Status::ProjectResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/blend/status/project_resolver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ ProjectResolver

Returns a new instance of ProjectResolver.



6
7
8
# File 'lib/blend/status/project_resolver.rb', line 6

def initialize( project )
  @project = project
end

Instance Attribute Details

#projectObject

Returns the value of attribute project.



4
5
6
# File 'lib/blend/status/project_resolver.rb', line 4

def project
  @project
end

Instance Method Details

#github_clientObject



14
15
16
# File 'lib/blend/status/project_resolver.rb', line 14

def github_client
  Blend::Client.github_client
end

#juice_clientObject



10
11
12
# File 'lib/blend/status/project_resolver.rb', line 10

def juice_client
  @project.juice_client
end

#nameObject



18
19
20
# File 'lib/blend/status/project_resolver.rb', line 18

def name
  @project.name
end

#resolve_github_membersObject



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/blend/status/project_resolver.rb', line 138

def resolve_github_members
  people = juice_client.organization_users(1).collect { |x| { name: x["name"], github: x['github_handle']}}.select { |x| set(x[:github]) }
  teams = @project.github_teams

  if teams.length == 0
    puts "Need to have a github team configured to add people to it!".red
    return
  end

  team = teams.first

  github = ""

  begin
    user = choose do |menu|

      menu.header = "Select a user"
      menu.prompt = "Please select a user"

      menu.choice "Done" do
        "done"
      end

      menu.choices *people.sort{|a,b| a[:name] <=> b[:name]}.collect { |x| "#{x[:github]}:#{x[:name]}"}
    end

    github = user.split( /:/ ).first

    if github != "done"
      github_client.add_team_member team, github
    end
  end while github != "done"
end

#resolve_github_teamsObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/blend/status/project_resolver.rb', line 80

def resolve_github_teams
  team = choose do |menu|
    menu.header = "Select a github team"
    menu.prompt = "Please select a team"

    menu.choice "Create a new team" do
      "create"
    end

    menu.choices *Blend::Client.juice_client.github_team_check.select { |k,v| v.length == 0}.keys
  end

  if team == "create"
    team = name.downcase
    puts "Creating team: #{name}"
    pp github_client.create_team( name.downcase )
  end

  if( set( team ))
    juice_client.project_add_team( @project.juice_id, team )
  end
end

#resolve_hipchatObject



42
43
44
45
46
47
48
49
50
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
# File 'lib/blend/status/project_resolver.rb', line 42

def resolve_hipchat
  puts "Resolve hipchat"

  choices = juice_client.hipchat_check.select do |x|
    x[:projects].first == "_unassigned_"
  end.collect do |x|
    x[:room]
  end

  if choices.member? name
    puts "Found a matching room... attaching"
    juice_client.project_add_hipchat( @project.juice_id, name )
    return
  end

  room = choose do |menu|
    menu.header = "Select a hipchat room action"
    menu.prompt = "Please choose a unassigned hipchat room to associate"
    menu.choice "Create A Room called #{name}" do
      "create"
    end

    menu.choices *choices
  end

  puts "You chose: #{room}"

  if room == "create"
    room = name
    puts "Creating a room #{name}"
    Blend::Client.hipchat_client.create_room( name, "Let's talk about #{name}!" )
  end

  if( set( room ) )
    juice_client.project_add_hipchat( @project.juice_id, name )
  end
end

#resolve_juice_users_syncedObject



172
173
174
175
176
177
178
179
180
# File 'lib/blend/status/project_resolver.rb', line 172

def resolve_juice_users_synced
  not_in_juice = @project.juice_users_synced_diff

  not_in_juice.each do |user_id|
    puts "Adding juice user_id: #{user_id}".yellow

    juice_client.project_add_user( @project.juice_id, user_id )
  end
end

#resolve_project_foundObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/blend/status/project_resolver.rb', line 26

def resolve_project_found
  puts "Trying to fix project_found"

  choose do |menu|
    menu.header = "No juice project found".red

    menu.prompt = "Create?"

    menu.choice "create" do
      juice_client.create_project @name
    end

    menu.choice "ignore"
  end
end

#resolve_repos_setupObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/blend/status/project_resolver.rb', line 103

def resolve_repos_setup
  teams = @project.github_teams

  if teams.length == 0
    puts "Need to have a github team configured to create a repo".red
    return
  end

  team = teams.first

  repos = @project.repos

  [ "", "-ios", "-android" ].each do |suffix|
    repo_name = "#{name}#{suffix}".downcase
    if repos.collect { |k,v| v }.select { |x,v| x['name'] == repo_name}.length > 0
      puts "Found #{repo_name}".green
    elsif agree "Create #{repo_name}? y/n ", true
      puts "Creating #{repo_name} in team #{team}".yellow
      github_client.repo_create( team, repo_name )
    end
  end
end

#resolve_source_controlObject



126
127
128
129
130
131
132
133
134
135
136
# File 'lib/blend/status/project_resolver.rb', line 126

def resolve_source_control
  repos = @project.repos_setup
  configured = (@project.feeds['github'] || []).collect { |x| "#{x['namespace']}/#{x['name']}" }

  (repos-configured).each do |repo|
    puts "Adding feed #{repo}".yellow

    pp juice_client.add_feed( @project.juice_id, 'github', repo )
  end
  # exit
end

#set(s) ⇒ Object



22
23
24
# File 'lib/blend/status/project_resolver.rb', line 22

def set( s )
  !s.nil? && s != ""
end