Class: Build::Repo

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

Direct Known Subclasses

RepoCocoapods, RepoModule, RepoXCode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, ssh_url, branch = nil) ⇒ Repo

Returns a new instance of Repo.



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/core_blur/repo.rb', line 23

def initialize(path, ssh_url, branch = nil)
  @ssh_url = ssh_url.to_s
  @branch = branch.to_s
  @path = path.to_s
  @repo_path = Pathname.new(path.to_s)
  @user_name = "jenkins"
  @user_email = "[email protected]"
  @last_commit = Commit.new
  @pusher = Push.instance
  __validate
end

Instance Attribute Details

#branchObject (readonly)

Returns the value of attribute branch.



13
14
15
# File 'lib/core_blur/repo.rb', line 13

def branch
  @branch
end

#gitlab_helperObject

Returns the value of attribute gitlab_helper.



14
15
16
# File 'lib/core_blur/repo.rb', line 14

def gitlab_helper
  @gitlab_helper
end

#http_urlObject (readonly)

Returns the value of attribute http_url.



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

def http_url
  @http_url
end

#last_commitObject

Returns the value of attribute last_commit.



20
21
22
# File 'lib/core_blur/repo.rb', line 20

def last_commit
  @last_commit
end

#page_urlObject (readonly)

Returns the value of attribute page_url.



10
11
12
# File 'lib/core_blur/repo.rb', line 10

def page_url
  @page_url
end

#pathObject

Returns the value of attribute path.



19
20
21
# File 'lib/core_blur/repo.rb', line 19

def path
  @path
end

#pusherObject

Returns the value of attribute pusher.



15
16
17
# File 'lib/core_blur/repo.rb', line 15

def pusher
  @pusher
end

#repo_pathObject

Returns the value of attribute repo_path.



18
19
20
# File 'lib/core_blur/repo.rb', line 18

def repo_path
  @repo_path
end

#sizeObject

Returns the value of attribute size.



21
22
23
# File 'lib/core_blur/repo.rb', line 21

def size
  @size
end

#size_formatObject

Returns the value of attribute size_format.



22
23
24
# File 'lib/core_blur/repo.rb', line 22

def size_format
  @size_format
end

#ssh_urlObject (readonly)

Returns the value of attribute ssh_url.



12
13
14
# File 'lib/core_blur/repo.rb', line 12

def ssh_url
  @ssh_url
end

#user_emailObject

Returns the value of attribute user_email.



17
18
19
# File 'lib/core_blur/repo.rb', line 17

def user_email
  @user_email
end

#user_nameObject

Returns the value of attribute user_name.



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

def user_name
  @user_name
end

Instance Method Details

#clearObject



116
117
118
119
120
121
122
123
# File 'lib/core_blur/repo.rb', line 116

def clear
  current = Dir.pwd
  Dir.chdir(self.path)
  command = 'ls | xargs rm -rf'
  puts "-> 清空仓库(#{File.basename(self.path)}):#{command}"
  system command
  Dir.chdir(current)
end

#discard_pullObject



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

def discard_pull
  current = Dir.pwd
  Dir.chdir(self.path)
  puts "丢弃修改并拉取代码"
  git_add_stag
  git_reset_hard
  git_fetch
  git_checkout(branch)
  git_pull
  Dir.chdir(current)
end

#git_add_stagObject



60
61
62
# File 'lib/core_blur/repo.rb', line 60

def git_add_stag
  GitHelper.add_stag(self.path)
end

#git_checkout(checkout_branch) ⇒ Object



81
82
83
# File 'lib/core_blur/repo.rb', line 81

def git_checkout(checkout_branch)
  GitHelper.checkout(self.path, checkout_branch)
end

#git_clone(only_head) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/core_blur/repo.rb', line 35

def git_clone(only_head)
  puts "\n(#{File.basename(self.path)})下载[#{self.ssh_url}] [#{self.branch}] [#{only_head ? "深度1" : "全量"}]"
  options = only_head ? {:depth => 1} : {}
  Git.clone(self.ssh_url, self.repo_path, branch: self.branch, options: options)
  repo = Git.open(self.repo_path)
  repo.config('user.name', user_name)
  repo.config('user.email', user_email)
  puts "完成"
  log = Git::Log.new(repo).first
  if log
    committer = log.committer
    puts "最近提交记录: [#{log.sha}] [#{log.message}] [#{committer.date}] [#{committer.name}] [#{committer.email}]"
    last_commit.commit_id = log.sha
    last_commit.commit_msg = log.message
    last_commit.committer = committer.name
    last_commit.commit_mail = committer.email
    last_commit.commit_time = committer.date.strftime("%Y-%m-%d %H:%M:%S")
  end
end

#git_commit(commit_msg = nil) ⇒ Object



63
64
65
# File 'lib/core_blur/repo.rb', line 63

def git_commit(commit_msg = nil)
  GitHelper.commit(self.path, commit_msg)
end

#git_fetchObject



78
79
80
# File 'lib/core_blur/repo.rb', line 78

def git_fetch
  GitHelper.fetch(self.path)
end

#git_pullObject



57
58
59
# File 'lib/core_blur/repo.rb', line 57

def git_pull
  GitHelper.pull(self.path)
end

#git_pushObject



66
67
68
# File 'lib/core_blur/repo.rb', line 66

def git_push
  GitHelper.push(self.path, self.branch)
end

#git_push_fObject



69
70
71
# File 'lib/core_blur/repo.rb', line 69

def git_push_f
  GitHelper.push_f(self.path, self.branch)
end

#git_push_tagsObject



72
73
74
# File 'lib/core_blur/repo.rb', line 72

def git_push_tags
  GitHelper.push_tags(self.path)
end

#git_reset_hardObject



75
76
77
# File 'lib/core_blur/repo.rb', line 75

def git_reset_hard
  GitHelper.reset_hard(self.path)
end

#git_statusObject



54
55
56
# File 'lib/core_blur/repo.rb', line 54

def git_status
  GitHelper.status(self.path)
end

#git_tag_delete_local(tag) ⇒ Object



84
85
86
# File 'lib/core_blur/repo.rb', line 84

def git_tag_delete_local(tag)
  GitHelper.tag_delete_local(self.path, tag)
end

#git_tag_delete_origin(tag) ⇒ Object



87
88
89
# File 'lib/core_blur/repo.rb', line 87

def git_tag_delete_origin(tag)
  GitHelper.tag_delete_origin(path, tag)
end

#git_tag_local(tag) ⇒ Object



90
91
92
# File 'lib/core_blur/repo.rb', line 90

def git_tag_local(tag)
  GitHelper.tag_local(self.path, tag)
end

#git_tag_origin(tag) ⇒ Object



93
94
95
# File 'lib/core_blur/repo.rb', line 93

def git_tag_origin(tag)
  GitHelper.tag_origin(self.path, tag)
end

#push_codeObject



107
108
109
110
111
112
113
114
115
# File 'lib/core_blur/repo.rb', line 107

def push_code
  puts "\n⏩ 推送产物(#{File.basename(self.path)})"
  git_pull
  if git_status
    git_add_stag
    git_commit(nil)
    git_push
  end
end