terraspace_vcs_gitlab 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: 25780a42633df6646392151671a824d0ab2ffb14cf9bc96a43181532aa34b11f
4
+ data.tar.gz: 7d0e7d9e59128af3dfce6c9c6b325b57efd404fe8fabd58d0f2a5d22b6c01673
5
+ SHA512:
6
+ metadata.gz: 229236a151d4f2c10f0bb9e66138b76f2f8194a8ba720b87d0cfcc6dc3b82258b37864871486913be51089b52d13b3b64e9fdb45d233a0883e06a8b3cb0905df
7
+ data.tar.gz: 5ae9f7699c1fb99a95e166e910aad8edaa5192b9ca9c7a60af7fa3c5248008ab39f6b99ea110cda810f63f4e565fccd8cdc6d75bd2d268ab51148736674207b3
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ This project *tries* to adhere to [Semantic Versioning](http://semver.org/).
5
+
6
+ ## [0.1.0] - 2022-07-07
7
+
8
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in gemspec
6
+ gemspec
7
+
8
+ gem "rake"
9
+ gem "rspec"
10
+ gem "rubocop"
11
+
12
+ group :development, :test do
13
+ gem "terraspace"
14
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) Tung Nguyen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # terraspace_vcs_gitlab
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/terraspace_vcs_gitlab.png)](http://badge.fury.io/rb/terraspace_vcs_gitlab)
4
+
5
+ [![BoltOps Badge](https://img.boltops.com/boltops/badges/boltops-badge.png)](https://www.boltops.com)
6
+
7
+ [![BoltOps Learn Badge](https://img.boltops.com/boltops-learn/boltops-learn.png)](https://learn.boltops.com)
8
+
9
+ Provides Terraspace VCS support for GitLab.
10
+
11
+ ## Installation
12
+
13
+ Add gem to your Terraspace project
14
+
15
+ Gemfile
16
+
17
+ gem terraspace_vcs_gitlab
18
+
19
+ Then to install run
20
+
21
+ bundle
22
+
23
+ ## Contributing
24
+
25
+ Bug reports and pull requests are welcome on GitHub at https://github.com/boltops-tools/terraspace_vcs_gitlab/
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,23 @@
1
+ require "zeitwerk"
2
+
3
+ module TerraspaceVcsGitlab
4
+ class Autoloader
5
+ class Inflector < Zeitwerk::Inflector
6
+ def camelize(basename, _abspath)
7
+ map = { version: "VERSION" }
8
+ map[basename.to_sym] || super
9
+ end
10
+ end
11
+
12
+ class << self
13
+ def setup
14
+ loader = Zeitwerk::Loader.new
15
+ loader.inflector = Inflector.new
16
+ loader.push_dir(File.dirname(__dir__)) # lib
17
+ loader.log! if ENV["TERRASPACE_VCS_GITLAB_AUTOLOAD_LOG"]
18
+ loader.setup
19
+ end
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,57 @@
1
+ require "gitlab"
2
+
3
+ module TerraspaceVcsGitlab
4
+ class Interface
5
+ extend Memoist
6
+ include Terraspace::Cloud::Vcs::Interface
7
+
8
+ def comment(body)
9
+ return unless gitlab_token?
10
+ return unless ENV['CI_PIPELINE_SOURCE'] == 'merge_request_event'
11
+
12
+ mr_number = pr_number
13
+ logger.debug "Adding comment to full_repo #{full_repo} mr_number #{mr_number}"
14
+ project = client.project(ENV['CI_PROJECT_PATH'])
15
+ merge_request = ENV['CI_MERGE_REQUEST_IID']
16
+
17
+ # https://www.rubydoc.info/gems/gitlab/Gitlab/Client/Notes
18
+ # TODO handle pagination
19
+ # TODO are we allow to post comment on public full_repo without need the permission?
20
+ notes = client.merge_request_notes(project.id, mr_number)
21
+ found_note = notes.find do |note|
22
+ note.body.starts_with?(MARKER)
23
+ end
24
+
25
+ if found_note
26
+ client.edit_merge_request_note(project.id, merge_request, found_note.id, body) unless found_note.body == body
27
+ else
28
+ client.create_merge_request_note(project.id, merge_request, body)
29
+ end
30
+ # Edge cases:
31
+ # token is not valid
32
+ # token is not right full_repo
33
+ rescue Gitlab::Error::Unauthorized => e
34
+ logger.info "WARN: #{e.message}. Unable to create merge request comment. Please double check your gitlab token"
35
+ rescue Gitlab::Error::Forbidden => e
36
+ logger.info "WARN: #{e.message}. Unable to create merge request comment. The token does not have the permission. Please double check your gitlab token"
37
+ end
38
+
39
+ def client
40
+ Gitlab.configure do |config|
41
+ config.endpoint = 'https://gitlab.com/api/v4'
42
+ config.private_token = ENV['GITLAB_TOKEN']
43
+ end
44
+ Gitlab.client
45
+ end
46
+ memoize :client
47
+
48
+ def gitlab_token?
49
+ if ENV['GITLAB_TOKEN']
50
+ true
51
+ else
52
+ puts "WARN: The env var GITLAB_TOKEN is not configured. Will not post MR comment"
53
+ false
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TerraspaceVcsGitlab
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "terraspace_vcs_gitlab/autoloader"
4
+ TerraspaceVcsGitlab::Autoloader.setup
5
+
6
+ require "json"
7
+ require "memoist"
8
+
9
+ module TerraspaceVcsGitlab
10
+ class Error < StandardError; end
11
+ end
12
+
13
+ require "terraspace"
14
+ Terraspace::Cloud::Vcs.register(
15
+ name: "gitlab",
16
+ )
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/terraspace_vcs_gitlab/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "terraspace_vcs_gitlab"
7
+ spec.version = TerraspaceVcsGitlab::VERSION
8
+ spec.authors = ["Tung Nguyen"]
9
+ spec.email = ["tung@boltops.com"]
10
+
11
+ spec.summary = "Terraspace VCS GitLab support"
12
+ spec.homepage = "https://github.com/boltops-tools/terraspace_vcs_gitlab"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/boltops-tools/terraspace_vcs_gitlab"
18
+ spec.metadata["changelog_uri"] = "https://github.com/boltops-tools/terraspace_vcs_gitlab/blob/master/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(__dir__) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
25
+ end
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency "gitlab"
32
+ spec.add_dependency "memoist"
33
+ spec.add_dependency "zeitwerk"
34
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: terraspace_vcs_gitlab
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tung Nguyen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-07-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gitlab
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: memoist
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: zeitwerk
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - tung@boltops.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".rspec"
63
+ - ".rubocop.yml"
64
+ - CHANGELOG.md
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/terraspace_vcs_gitlab.rb
70
+ - lib/terraspace_vcs_gitlab/autoloader.rb
71
+ - lib/terraspace_vcs_gitlab/interface.rb
72
+ - lib/terraspace_vcs_gitlab/version.rb
73
+ - terraspace_vcs_gitlab.gemspec
74
+ homepage: https://github.com/boltops-tools/terraspace_vcs_gitlab
75
+ licenses:
76
+ - MIT
77
+ metadata:
78
+ homepage_uri: https://github.com/boltops-tools/terraspace_vcs_gitlab
79
+ source_code_uri: https://github.com/boltops-tools/terraspace_vcs_gitlab
80
+ changelog_uri: https://github.com/boltops-tools/terraspace_vcs_gitlab/blob/master/CHANGELOG.md
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 2.6.0
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubygems_version: 3.3.12
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Terraspace VCS GitLab support
100
+ test_files: []