pixab 2.2.1 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40bdedbf96ae1aad98cea6889c0cd32dafc9d9d6634ed181ea5d3aad9fc50c53
4
- data.tar.gz: f097ad80dcff665eb3f0e6a77f7717fbed41bc7e7503e6819a09e0591e5b43f2
3
+ metadata.gz: 7e4ecbfcfe6d0ab2d1d8ee3f3df1260f010a390779ebd217b7f277dd6fe62e40
4
+ data.tar.gz: d6545ec0fb08269c0454f3dda5606d45b2233d4a15ccc1c9b646ca7e4acc6885
5
5
  SHA512:
6
- metadata.gz: 74c4e32db81e84edf7d54c6a7bf719290bf458978440435e231113ba1e08eefb6dc659934742f295a1660733887c4adbb24f00f408adc303c22e050a57264d4f
7
- data.tar.gz: fec66d4eac0ed930fa2052a3d02d77e8a482b1da15edf8f068e6fdbb5c98f81bf25649b0bdf0d707115fa54b15b69639dd192a3ce3ec7313040a622f59ccf705
6
+ metadata.gz: 5a88385f99379bf784232c343f6e04b08a7d908eb8f29df0f8dc6aca21de69fba4f72b2b3d68124a6dfa35cb6948d06fd5792f6bda4779a22fd9e5a81ae3b271
7
+ data.tar.gz: 18b809e1f690cc39ae2b96b982c3f6bfb77e9971804b185f853bd9819938fffd86d5300bc8a3c5134f894ea9197ed70ed7676773c075e5c33c1ab02e27964dd8
@@ -1,3 +1,5 @@
1
+ require 'yaml'
2
+
1
3
  module Pixab
2
4
 
3
5
  class GitlabInfo
@@ -5,8 +7,8 @@ module Pixab
5
7
  # Gitlab API endpoint
6
8
  API_ENDPOINT = 'https://techgit.meitu.com/api/v4'
7
9
 
8
- # Gitlab private token
9
- TOKEN = 'glpat-BZWgys9gsAQ8mnGYTajr'
10
+ # Gitlab token key
11
+ TOKEN_KEY = 'user_token'
10
12
 
11
13
  end
12
14
 
@@ -58,6 +60,37 @@ module Pixab
58
60
  end
59
61
  end
60
62
 
63
+ def get_config
64
+ config_file = get_config_file
65
+ if File.exist?(config_file)
66
+ return YAML.load_file(config_file)
67
+ else
68
+ return {}
69
+ end
70
+ end
71
+
72
+ def get_user_token
73
+ config = get_config
74
+ return config[GitlabInfo::TOKEN_KEY]
75
+ end
76
+
77
+ def set_user_token(token)
78
+ config = get_config
79
+ config[GitlabInfo::TOKEN_KEY] = token
80
+ config_dir = get_config_dir
81
+ config_file = get_config_file
82
+ Dir.mkdir(config_dir) unless Dir.exist?(config_dir)
83
+ File.write(config_file, config.to_yaml)
84
+ end
85
+
86
+ def get_config_dir
87
+ File.expand_path('~/.pixab')
88
+ end
89
+
90
+ def get_config_file
91
+ File.join(get_config_dir, 'mrConfig.yml')
92
+ end
93
+
61
94
  end
62
95
 
63
96
  end
@@ -9,6 +9,10 @@ module Pixab
9
9
 
10
10
  class GitlabMR
11
11
 
12
+ def initialize(token)
13
+ @token = token
14
+ end
15
+
12
16
  def run(path, reviewers_ids)
13
17
  unless Dir.exist?(path)
14
18
  puts "当前目录不存在: #{path}".red
@@ -45,7 +49,7 @@ module Pixab
45
49
 
46
50
  # 构建 HTTP 请求
47
51
  request = Net::HTTP::Post.new(uri)
48
- request['PRIVATE-TOKEN'] = GitlabInfo::TOKEN
52
+ request['PRIVATE-TOKEN'] = @token
49
53
  request['Content-Type'] = 'application/json'
50
54
 
51
55
  body = {
@@ -94,7 +98,7 @@ module Pixab
94
98
 
95
99
  uri = URI("#{GitlabInfo::API_ENDPOINT}/projects/#{URI.encode_www_form_component(project_path)}")
96
100
  request = Net::HTTP::Get.new(uri)
97
- request['PRIVATE-TOKEN'] = GitlabInfo::TOKEN
101
+ request['PRIVATE-TOKEN'] = @token
98
102
 
99
103
  http = Net::HTTP.new(uri.hostname, uri.port)
100
104
  http.use_ssl = (uri.scheme == 'https') # 如果是 HTTPS,启用 SSL
@@ -10,7 +10,6 @@ module Pixab
10
10
 
11
11
  def run(commands = nil)
12
12
  platform = nil
13
-
14
13
  if not commands.nil?
15
14
  commands.each_index do |index|
16
15
  command = commands[index]
@@ -19,6 +18,11 @@ module Pixab
19
18
  platform = Platform.new('android')
20
19
  when '--iOS'
21
20
  platform = Platform.new('iOS')
21
+ when '--token'
22
+ token = commands[index + 1]
23
+ unless token.nil?
24
+ GitlabInfo.set_user_token(token)
25
+ end
22
26
  end
23
27
  end
24
28
  end
@@ -27,6 +31,12 @@ module Pixab
27
31
  platform = Platform.new('iOS')
28
32
  end
29
33
 
34
+ token = GitlabInfo.get_user_token
35
+ if token.nil?
36
+ puts "未设置 Gitlab Token".red
37
+ return
38
+ end
39
+
30
40
  git_repos = Pixab::GitlabMRManager.new.find_git_repos(Dir.pwd)
31
41
 
32
42
  if git_repos.empty?
@@ -54,7 +64,7 @@ module Pixab
54
64
  end
55
65
  end
56
66
 
57
- gitlab_mr = GitlabMR.new
67
+ gitlab_mr = GitlabMR.new(token)
58
68
  git_repos.each do |repo|
59
69
  gitlab_mr.run(repo, reviewer_ids)
60
70
  end
data/lib/pixab/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pixab
4
- VERSION = "2.2.1"
4
+ VERSION = "2.2.2"
5
5
  end
data/pixab.gemspec CHANGED
@@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
37
37
  spec.add_dependency 'rubyzip'
38
38
  spec.add_dependency 'nokogiri'
39
39
  spec.add_dependency 'rest-client'
40
+ spec.add_dependency 'yaml'
40
41
 
41
42
  # For more information and examples about making a new gem, check out our
42
43
  # guide at: https://bundler.io/guides/creating_gem.html
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pixab
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - 廖再润
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yaml
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Write a longer description or delete this line.
70
84
  email:
71
85
  - lzr3@us.meitu.com