fastlane-plugin-gitlab_changelog 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +75 -0
- data/lib/fastlane/plugin/gitlab_changelog.rb +16 -0
- data/lib/fastlane/plugin/gitlab_changelog/actions/gitlab_changelog_action.rb +80 -0
- data/lib/fastlane/plugin/gitlab_changelog/helper/gitlab_changelog_helper.rb +18 -0
- data/lib/fastlane/plugin/gitlab_changelog/version.rb +5 -0
- metadata +174 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ad928ae4d6868eb41ebee3905d1bea6f2bc457cbb9e8c11dde54b2a1a7d66026
|
4
|
+
data.tar.gz: ce9ff718fd01887a1901672e0701307a8d49a4a5b2ed97e5e8625b1d81b9a9c6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b88e17af0bc8aaa9372fbcdbf85aaf18302fc6e1071b37448fda47f9aad9339efe17f7e4cb6a23cf237ec2a32e9b363b978f5b89e0e99c6cd6ceeae0d09298e4
|
7
|
+
data.tar.gz: 77fa75cfeb39037397b182270959a54f9f7da583d502a809143f0b4cdf61d7005d2c77e2ca3a06a256a2adc4ecb78e1fd79ec736e4d8d9345cd7f41cf69d1c5a
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Treatwell <zilvinas.sebeika@wahanda.com>
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# gitlab_changelog plugin
|
2
|
+
|
3
|
+
[![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-gitlab_changelog)
|
4
|
+
|
5
|
+
## Getting Started
|
6
|
+
|
7
|
+
This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-gitlab_changelog`, add it to your project by running:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
fastlane add_plugin gitlab_changelog
|
11
|
+
```
|
12
|
+
|
13
|
+
## About gitlab_changelog
|
14
|
+
|
15
|
+
Get commit changelog using GitLab API
|
16
|
+
|
17
|
+
Plugin is particularly useful if you use [Shallow Cloning](https://docs.gitlab.com/ee/ci/large_repositories/#shallow-cloning) and have small number, like `GIT_DEPTH: "1"`, setting in your GitLab CI config.
|
18
|
+
|
19
|
+
In such case, `Fastlane's` native [`changelog_from_git_commits`](https://docs.fastlane.tools/actions/changelog_from_git_commits/#changelog_from_git_commits) action is not helpful, because CI machine does not have a full git history to construct a changelog.
|
20
|
+
|
21
|
+
This plugin resolves latest release branch using [`git ls-remote`](https://git-scm.com/docs/git-ls-remote.html) (always available).
|
22
|
+
|
23
|
+
```bash
|
24
|
+
git ls-remote --sort='v:refname' --heads origin refs/heads/release/*```
|
25
|
+
```
|
26
|
+
refs/heads/release/4.267.0
|
27
|
+
refs/heads/release/4.269.0
|
28
|
+
refs/heads/release/4.269.1
|
29
|
+
refs/heads/release/4.270.0
|
30
|
+
refs/heads/release/4.270.1
|
31
|
+
|
32
|
+
And then, fetches a changelog (JSON) between the current branch and the latest release branch using [`GitLab API`](https://docs.gitlab.com/ee/api/repositories.html#compare-branches-tags-or-commits).
|
33
|
+
|
34
|
+
In a case then CI _is_ on release branch currently - a changelog between current and previous release branches is constructed.
|
35
|
+
|
36
|
+
## Usage:
|
37
|
+
```
|
38
|
+
change_log = gitlab_changelog(
|
39
|
+
current_branch: "develop",
|
40
|
+
compare_branch_prefix: "release",
|
41
|
+
gitlab_API_baseURL: "http://git.yourcompany.net/api/v4",
|
42
|
+
gitlab_project_id: "123",
|
43
|
+
gitlab_API_token: "secret_gitlab_token"
|
44
|
+
)
|
45
|
+
```
|
46
|
+
|
47
|
+
**Params:**
|
48
|
+
* _current_branch_ : `Actions.git_branch` or `ENV['CI_COMMIT_REF_NAME']` (default)
|
49
|
+
* _compare_branch_prefix_ : default is `release` to compare against `release/*.*.*` branches
|
50
|
+
* _gitlab_API_baseURL_ : a root URL for your GitLab API
|
51
|
+
* _gitlab_project_id_ : `ENV['CI_PROJECT_ID']` (default)
|
52
|
+
* _gitlab_API_token_ : Create a GitLab API Token and define it as a variable on your CI environment like `ENV['MY_GITLAB_API_TOKEN']`
|
53
|
+
|
54
|
+
**Output:**
|
55
|
+
_Fetching changeLog from: release/4.270.1 to: develop (GET http://git.yourcompany.net/api/v4/projects/123/repository/compare)_
|
56
|
+
|
57
|
+
DEV0001 Feature 2 (Thom Yorke) 2019-12-31
|
58
|
+
DEV0002 Feature 1 (Jonny Greenwood) 2019-12-30
|
59
|
+
|
60
|
+
## Issues and Feedback
|
61
|
+
|
62
|
+
For any other issues and feedback about this plugin, please submit it to this repository.
|
63
|
+
|
64
|
+
## Troubleshooting
|
65
|
+
|
66
|
+
If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
|
67
|
+
|
68
|
+
## Using _fastlane_ Plugins
|
69
|
+
|
70
|
+
For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
|
71
|
+
|
72
|
+
## About _fastlane_
|
73
|
+
|
74
|
+
_fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
|
75
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'fastlane/plugin/gitlab_changelog/version'
|
2
|
+
|
3
|
+
module Fastlane
|
4
|
+
module GitlabChangelog
|
5
|
+
# Return all .rb files inside the "actions" and "helper" directory
|
6
|
+
def self.all_classes
|
7
|
+
Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# By default we want to import all available actions and helpers
|
13
|
+
# A plugin can contain any number of actions and plugins
|
14
|
+
Fastlane::GitlabChangelog.all_classes.each do |current|
|
15
|
+
require current
|
16
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/gitlab_changelog_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
class GitlabChangelogAction < Action
|
7
|
+
def self.run(params)
|
8
|
+
require 'excon'
|
9
|
+
|
10
|
+
to_branch = params[:current_branch].to_s
|
11
|
+
from_branch = Helper::GitlabChangelogHelper.get_from_branch(params[:compare_branch_prefix].to_s, to_branch)
|
12
|
+
endpoint = "#{params[:gitlab_API_baseURL]}/projects/#{params[:gitlab_project_id]}/repository/compare"
|
13
|
+
|
14
|
+
UI.message("Fetching changeLog from: #{from_branch} to: #{to_branch} (GET #{endpoint})")
|
15
|
+
|
16
|
+
compare_resp = Excon.get(
|
17
|
+
endpoint,
|
18
|
+
query: {
|
19
|
+
from: from_branch,
|
20
|
+
to: to_branch,
|
21
|
+
private_token: params[:gitlab_API_token]
|
22
|
+
}
|
23
|
+
)
|
24
|
+
|
25
|
+
change_log = JSON.parse(compare_resp.body)['commits']
|
26
|
+
.reject { |c| c['title'].start_with?("Merge branch") } # Filter out merges
|
27
|
+
.sort_by { |c| -Date.parse(c['created_at']).to_time.to_i }
|
28
|
+
.map { |c| "#{c['title']} (#{c['author_name']}) #{Date.parse(c['created_at'])}" }
|
29
|
+
.join("\n")
|
30
|
+
|
31
|
+
puts("\n#{change_log}")
|
32
|
+
|
33
|
+
change_log
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.description
|
37
|
+
"Get changelog using GitLab API"
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.authors
|
41
|
+
["Žilvinas Sebeika"]
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.return_value
|
45
|
+
"String containing commit messages (excluding branch merges). Separated by new_line"
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.details
|
49
|
+
"Fetch changelog between branches using GitLab API. Useful if you have GIT_DEPTH: 1 setting in CI config"
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.available_options
|
53
|
+
[
|
54
|
+
FastlaneCore::ConfigItem.new(key: :current_branch,
|
55
|
+
env_name: "CI_COMMIT_REF_NAME",
|
56
|
+
description: "Current branch",
|
57
|
+
optional: false),
|
58
|
+
FastlaneCore::ConfigItem.new(key: :compare_branch_prefix,
|
59
|
+
default_value: "release",
|
60
|
+
description: "Compare branch prefix. Usually 'release' to compare against 'release/*.*.*' branches",
|
61
|
+
optional: false),
|
62
|
+
FastlaneCore::ConfigItem.new(key: :gitlab_API_baseURL,
|
63
|
+
description: "GitLab API base URL (http://<gitLab_host>/api/v4)",
|
64
|
+
optional: false),
|
65
|
+
FastlaneCore::ConfigItem.new(key: :gitlab_project_id,
|
66
|
+
env_name: "CI_PROJECT_ID",
|
67
|
+
description: "GitLab Project ID (ENV['CI_PROJECT_ID'])",
|
68
|
+
optional: false),
|
69
|
+
FastlaneCore::ConfigItem.new(key: :gitlab_API_token,
|
70
|
+
description: "GitLab API Token (ENV['GITLAB_API_TOKEN'])",
|
71
|
+
optional: false)
|
72
|
+
]
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.is_supported?(platform)
|
76
|
+
true
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Fastlane
|
2
|
+
module Helper
|
3
|
+
class GitlabChangelogHelper
|
4
|
+
def self.get_depth(name, current_branch)
|
5
|
+
current_branch.start_with?(name) ? 2 : 1
|
6
|
+
end
|
7
|
+
|
8
|
+
# If the current branch is a branch we're comparing to ("release/*.*.*" for example) -
|
9
|
+
# then pick depth = 2 to get a previous version number for the changelog.
|
10
|
+
# Otherwise - use the latest version as a reference branch.
|
11
|
+
def self.get_from_branch(name, current_branch)
|
12
|
+
depth = get_depth(name, current_branch)
|
13
|
+
reference_branch = Action.sh("git ls-remote --sort='v:refname' --quiet --heads origin refs/heads/#{name}/* | tail -n #{depth} | head -n 1 | awk '{ printf \"%s\", $2 }' | rev | cut -d/ -f1 | rev | xargs echo -n")
|
14
|
+
return "#{name}/#{reference_branch}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fastlane-plugin-gitlab_changelog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Žilvinas Sebeika
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-01-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec_junit_formatter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.49.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.49.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-require_tools
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: fastlane
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 2.136.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 2.136.0
|
139
|
+
description:
|
140
|
+
email: zilvinas.sebeika@wahanda.com
|
141
|
+
executables: []
|
142
|
+
extensions: []
|
143
|
+
extra_rdoc_files: []
|
144
|
+
files:
|
145
|
+
- LICENSE
|
146
|
+
- README.md
|
147
|
+
- lib/fastlane/plugin/gitlab_changelog.rb
|
148
|
+
- lib/fastlane/plugin/gitlab_changelog/actions/gitlab_changelog_action.rb
|
149
|
+
- lib/fastlane/plugin/gitlab_changelog/helper/gitlab_changelog_helper.rb
|
150
|
+
- lib/fastlane/plugin/gitlab_changelog/version.rb
|
151
|
+
homepage: https://github.com/treatwell/fastlane-plugin-gitlab_changelog.git
|
152
|
+
licenses:
|
153
|
+
- MIT
|
154
|
+
metadata: {}
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubygems_version: 3.0.1
|
171
|
+
signing_key:
|
172
|
+
specification_version: 4
|
173
|
+
summary: Get changelog using GitLab API
|
174
|
+
test_files: []
|