versionbot 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a228dd08b2361155fe3a5b50e3abff26d5e278c4c9146bbede313576bc4e64b0
4
+ data.tar.gz: 173a82a281875ddcb9017251bdc93d0896168354ca7968a8e77a5b1f9bafa01f
5
+ SHA512:
6
+ metadata.gz: d71887e146e33c020f0639985741a08e7abecf700e4e2e28547c27050da3c5ce606f501c9862712af44a35c6bc54ab883996426fd4f6357106bd32fce9460296
7
+ data.tar.gz: cc9da03ee457deb76abe01f716e759871d0ca335c4d376f64c2be88061b35e2edc07127dc51204ae39debc432192568566d65f27308c91ad855b8cdc52688643
data/.standard.yml ADDED
@@ -0,0 +1,2 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
@@ -0,0 +1,22 @@
1
+ {
2
+ "workbench.colorCustomizations": {
3
+ "activityBar.activeBackground": "#afd0e5",
4
+ "activityBar.activeBorder": "#c8579c",
5
+ "activityBar.background": "#afd0e5",
6
+ "activityBar.foreground": "#15202b",
7
+ "activityBar.inactiveForeground": "#15202b99",
8
+ "activityBarBadge.background": "#c8579c",
9
+ "activityBarBadge.foreground": "#15202b",
10
+ "sash.hoverBorder": "#afd0e5",
11
+ "statusBar.background": "#88b9d9",
12
+ "statusBar.foreground": "#15202b",
13
+ "statusBarItem.hoverBackground": "#61a2cd",
14
+ "statusBarItem.remoteBackground": "#88b9d9",
15
+ "statusBarItem.remoteForeground": "#15202b",
16
+ "titleBar.activeBackground": "#88b9d9",
17
+ "titleBar.activeForeground": "#15202b",
18
+ "titleBar.inactiveBackground": "#88b9d999",
19
+ "titleBar.inactiveForeground": "#15202b99"
20
+ },
21
+ "peacock.remoteColor": "#88b9d9"
22
+ }
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in versionbot.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "standard", "~> 1.3"
data/Gemfile.lock ADDED
@@ -0,0 +1,67 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ versionbot (0.1.0)
5
+ faraday
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ diff-lcs (1.5.0)
12
+ faraday (2.2.0)
13
+ faraday-net_http (~> 2.0)
14
+ ruby2_keywords (>= 0.0.4)
15
+ faraday-net_http (2.0.1)
16
+ parallel (1.22.0)
17
+ parser (3.1.1.0)
18
+ ast (~> 2.4.1)
19
+ rainbow (3.1.1)
20
+ rake (13.0.6)
21
+ regexp_parser (2.2.1)
22
+ rexml (3.2.5)
23
+ rspec (3.11.0)
24
+ rspec-core (~> 3.11.0)
25
+ rspec-expectations (~> 3.11.0)
26
+ rspec-mocks (~> 3.11.0)
27
+ rspec-core (3.11.0)
28
+ rspec-support (~> 3.11.0)
29
+ rspec-expectations (3.11.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.11.0)
32
+ rspec-mocks (3.11.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.11.0)
35
+ rspec-support (3.11.0)
36
+ rubocop (1.26.0)
37
+ parallel (~> 1.10)
38
+ parser (>= 3.1.0.0)
39
+ rainbow (>= 2.2.2, < 4.0)
40
+ regexp_parser (>= 1.8, < 3.0)
41
+ rexml
42
+ rubocop-ast (>= 1.16.0, < 2.0)
43
+ ruby-progressbar (~> 1.7)
44
+ unicode-display_width (>= 1.4.0, < 3.0)
45
+ rubocop-ast (1.16.0)
46
+ parser (>= 3.1.1.0)
47
+ rubocop-performance (1.13.3)
48
+ rubocop (>= 1.7.0, < 2.0)
49
+ rubocop-ast (>= 0.4.0)
50
+ ruby-progressbar (1.11.0)
51
+ ruby2_keywords (0.0.5)
52
+ standard (1.8.0)
53
+ rubocop (= 1.26.0)
54
+ rubocop-performance (= 1.13.3)
55
+ unicode-display_width (2.1.0)
56
+
57
+ PLATFORMS
58
+ x86_64-linux
59
+
60
+ DEPENDENCIES
61
+ rake (~> 13.0)
62
+ rspec (~> 3.2)
63
+ standard (~> 1.3)
64
+ versionbot!
65
+
66
+ BUNDLED WITH
67
+ 2.3.4
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Versionbot
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/versionbot`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'versionbot'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install versionbot
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/versionbot.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "standard/rake"
5
+
6
+ task default: :standard
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "versionbot"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/versionbot ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'versionbot'
4
+
5
+ unless ARGV.size == 1
6
+ puts "usage: versionbot <Codebase Group>"
7
+ return
8
+ end
9
+
10
+ STDOUT.puts Versionbot.find_from_cli(ARGV[0])
11
+
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Versionbot
4
+ VERSION = "0.1.0".freeze
5
+ end
data/lib/versionbot.rb ADDED
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+ require 'singleton'
3
+ require_relative "versionbot/version"
4
+ require 'faraday'
5
+ require 'faraday/net_http'
6
+ Faraday.default_adapter = :net_http
7
+
8
+ module Versionbot
9
+ class Error < StandardError; end
10
+
11
+ def self.gen_version(group)
12
+ Bot.instance.gen_version(group)
13
+ end
14
+
15
+ def self.gen_from_cli(group)
16
+ result = self.gen_version(group)
17
+ JSON.generate(result)
18
+ end
19
+
20
+ class Bot
21
+ include ::Singleton
22
+
23
+ @@access_token = nil
24
+
25
+ def self.access_token(token)
26
+ @@access_token = token
27
+ end
28
+
29
+ def gen_version(group)
30
+ unless (@@access_token.is_a? String) && @@access_token.size > 0
31
+ @@access_token = ENV["VERSIONBOT_TOKEN"]
32
+ end
33
+
34
+ conn = Faraday.new("http://code.yiye.ai") do |f|
35
+ f.request :json
36
+ f.response :json
37
+ f.headers = {
38
+ "Content-Type" => "application/json",
39
+ "PRIVATE-TOKEN" => @@access_token
40
+ }
41
+ end
42
+ projects = fetch_data(conn, "/api/v4/groups/#{group}/projects?archived=false")
43
+ if projects.nil?
44
+ return {error_msg: "group not exists or server is broken", data: {}}
45
+ end
46
+
47
+ max_ver = "0.0.0"
48
+ ver_map = {}
49
+ projects.each do |prj|
50
+ latest_tag = fetch_data(conn, "/api/v4/projects/#{prj["id"]}/repository/tags?per_page=1")
51
+ unless latest_tag.nil? || latest_tag.size == 0
52
+ max_ver = max_version(max_ver, latest_tag[0]["name"])
53
+ ver_map[prj["path_with_namespace"]] = latest_tag[0]["name"]
54
+ end
55
+ end
56
+ {error_msg: nil, data: {max_version: max_ver, version_map: ver_map}}
57
+ end
58
+
59
+ def fetch_data(conn, url)
60
+ resp = conn.get(url)
61
+ status = resp.status
62
+ if status == 200
63
+ resp.body
64
+ else
65
+ nil
66
+ end
67
+ end
68
+
69
+ def max_version(cur, income)
70
+ if cur.start_with? 'v'
71
+ cur = cur[1..-1]
72
+ end
73
+ if income.start_with? 'v'
74
+ income = income[1..-1]
75
+ end
76
+ cur_major, cur_minor, cur_bugfix = cur.split('.')
77
+ income_major, income_minor, income_bugfix = income.split('.')
78
+ #
79
+ cur_num = cur_major.to_i * 10000 + cur_minor.to_i * 10 + cur_bugfix.to_i
80
+ income_num = income_major.to_i * 10000 + income_minor.to_i * 10 + income_bugfix.to_i
81
+
82
+ if cur_num > income_num
83
+ return cur
84
+ else
85
+ return income
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,4 @@
1
+ module Versionbot
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: versionbot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Forwaard
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ description: a version bot to help yiyetech dev team to set release version
42
+ email:
43
+ - forwaard@163.com
44
+ executables:
45
+ - versionbot
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".standard.yml"
50
+ - ".vscode/settings.json"
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - bin/versionbot
58
+ - lib/versionbot.rb
59
+ - lib/versionbot/version.rb
60
+ - sig/versionbot.rbs
61
+ homepage:
62
+ licenses: []
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 2.6.0
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubygems_version: 3.3.3
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: a version bot to help yiyetech dev team to set release version
83
+ test_files: []