Class: Repositories

Inherits:
Object
  • Object
show all
Defined in:
lib/actions/repo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRepositories

scope = 1 -> organization repos scope = 2 -> user repos scope = 3 -> team repos



16
17
18
# File 'lib/actions/repo.rb', line 16

def initialize
  @reposlist=[]
end

Instance Attribute Details

#reposlistObject (readonly)

Returns the value of attribute reposlist.



11
12
13
# File 'lib/actions/repo.rb', line 11

def reposlist
  @reposlist
end

Instance Method Details

#clone_repo(client, config, exp, scope) ⇒ Object

clone repositories exp = regular expression



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/actions/repo.rb', line 197

def clone_repo(client,config,exp,scope)
  web="https://github.com/"
  web2="[email protected]:"

  if exp.match(/^\//)
    exps=exp.split('/')
    list=self.get_repos_list(client,config,scope)
    list=Sys.new.search_rexp(list,exps[1])
  else
    list=[]
    list.push(exp)
  end

  if (list.empty?) == false
    case
    when scope==1
      list.each do |i|
        command = "git clone #{web}#{config["User"]}/#{i}.git"
        system(command)
      end
    when scope==2
      list.each do |i|
        command = "git clone #{web}#{config["Org"]}/#{i}.git"
        system(command)
      end
    end
  else
    puts "No repositories found it with the parameters given"
  end
end

#create_repository(client, config, repo, scope) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/actions/repo.rb', line 144

def create_repository(client,config,repo,scope)
  options=Hash.new
  case
  when scope==2
    puts "created repository in org"
    options[:organization]=config["Org"]
    client.create_repository(repo,options)
  when scope==1
    puts "created repository in user"
    client.create_repository(repo)
  when scope==4
    puts "created repository in org team"
    options[:team_id]=config["TeamID"]
    options[:organization]=config["Org"]
    client.create_repository(config["Team"]+"/"+repo,options)
  end
end

#create_repository_by_teamlist(client, config, repo, list, list_id) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/actions/repo.rb', line 162

def create_repository_by_teamlist(client,config,repo,list,list_id)
  options=Hash.new
  options[:organization]=config["Org"]
  #puts list_id
  y=0
  list.each do |i|
    options[:team_id]=list_id[y]
    # puts i, list_id[y]
    # puts repo
    # puts options
    # puts "\n"
    client.create_repository(i+"/"+repo,options)
    y=y+1
  end
end

#fork(client, config, repo) ⇒ Object



139
140
141
142
# File 'lib/actions/repo.rb', line 139

def fork(client,config,repo)
  mem=client.fork(repo)
  return mem
end

#get_repos_list(client, config, scope) ⇒ Object

Gete the repository list from a given scope



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/actions/repo.rb', line 179

def get_repos_list(client,config,scope)
  reposlist=[]
  case
    when scope==1
      repo=client.repositories
    when scope==2
      repo=client.organization_repositories(config["Org"])
    when scope==4
      repo=client.team_repositories(config["TeamID"])
  end
  repo.each do |i|
    reposlist.push(i.name)
  end
  return reposlist
end

#show_collaborators(client, config, scope) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/actions/repo.rb', line 124

def show_collaborators(client,config,scope)
  print "\n"
  collalist=[]
  case
  when scope==1
    mem=client.collaborators(config["Org"]+"/"+config["Repo"])
  end
  mem.each do |i|
    puts i[:author][:login]
    collalist.push(i[:author][:login])
  end
  print "\n"
  return collalist
end

#show_commits(client, config, scope) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/actions/repo.rb', line 20

def show_commits(client,config,scope)
  print "\n"
  case
    when scope==1
      mem=client.commits(config["Org"]+"/"+config["Repo"],"master")
    when scope==2
      mem=client.commits(config["User"]+"/"+config["Repo"],"master")
  end
  mem.each do |i|
    print i[:sha],"\n",i[:commit][:author][:name],"\n",i[:commit][:author][:date],"\n",i[:commit][:message],"\n\n"
  end
end

#show_forks(client, config, scope) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/actions/repo.rb', line 109

def show_forks(client,config,scope)
  print "\n"
  forklist=[]
  case
    when scope==1
      mem=client.forks(config["Org"]+"/"+config["Repo"])
  end
  mem.each do |i|
    puts i[:owner][:login]
    forklist.push(i[:owner][:login])
  end
  print "\n"
  return forklist
end

#show_repos(client, config, scope, exp) ⇒ Object

Show repositories and return a list of them exp = regular expression



35
36
37
38
39
40
41
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/actions/repo.rb', line 35

def show_repos(client,config,scope,exp)
  print "\n"
  rlist=[]
  options=Hash.new
  o=Organizations.new
  regex=false

  if exp!=nil
    if exp.match(/^\//)
      regex=true
      sp=exp.split('/')
      exp=Regexp.new(sp[1],sp[2])
    end
  end

  case
    when scope==1
      repo=client.repositories(options) #config["User"]
      listorgs=o.read_orgs(client)

    when scope==2
      repo=client.organization_repositories(config["Org"])
    when scope==4
      repo=client.team_repositories(config["TeamID"])
  end

  counter=0
  allpages=true

  repo.each do |i|
    if regex==false
      if counter==100 && allpages==true
        op=Readline.readline("\nThere are more results. Show next repositories (press any key) or Show all repositories (press a): ",true)
        if op=="a"
          allpages=false
        end
        counter=0
      end

      puts i.name
      rlist.push(i.name)
      counter=counter+1
    else

    if i.name.match(exp)
        puts i.name
        rlist.push(i.name)
        counter=counter+1
      end
    end
  end

  if rlist.empty?
    puts "No repository matches with that expression"
  else
    print "\n"
    puts "Repositories found: #{rlist.size}"
  end

  return rlist
end

#show_user_orgs_repos(client, config, listorgs) ⇒ Object



97
98
99
100
101
102
103
104
105
106
# File 'lib/actions/repo.rb', line 97

def show_user_orgs_repos(client,config,listorgs)
  options=Hash.new
  options[:member]=config["User"]
  listorgs.each do |i|
    repo=client.organization_repositories(i,options)
        repo.each do |y|
          puts y.name
        end
  end
end