sashimi_tanpopo 0.1.3 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 263eb474146609f7c441ccb77681664ad19846e6aac8d7585fc7a583a08167a1
4
- data.tar.gz: ddc2b35d0e3e8db88b6ff954c815446bf4c71539ca29f246c3c026ddb10b7b48
3
+ metadata.gz: d1e88131c30bb63dca71cc98bcec3900ab0288e503ce90097335c34789263552
4
+ data.tar.gz: e7daeebcc079716289560e8cf82ee551c992d1bd15feda824dee74af915bc316
5
5
  SHA512:
6
- metadata.gz: 96ef60917e18568424cfe95f741223bcc7a84c66878751d57b2838b1201ee55c53e1e1102c541d3f6864bfe1a14555ce4ca0e8f67938a51981c86298088eaf5b
7
- data.tar.gz: 8953c7816ff996d4bd32d30cecdcbdce5506102afff9a0284242631d1d23786c1d39e0f60875658c4031c03c4f17f9e169beecde1d1c72d40d9fd58077d88dc5
6
+ metadata.gz: 8d16cfb0656499041cb3364d990378b86151d9bcb7f613c8c109913e27c9e5c3b19c5e815a126c2090f132d6138845bade0c25ba1e42431cb2292ac6d5212ce2
7
+ data.tar.gz: 28d6a9a83e060325e5111d34ea8031d424a54d280dbe57f52f83e43af86decb4055ebc449b55d852ba7dcd591c65a848107c2a2a2a06fd8eb8327ac62057575d
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  ## [Unreleased]
2
2
  [full changelog](http://github.com/sue445/sashimi_tanpopo/compare/v0.1.3...main)
3
3
 
4
+ ## [0.2.0](https://github.com/sue445/sashimi_tanpopo/releases/tag/v0.2.0) - 2025-10-22
5
+ [full changelog](http://github.com/sue445/sashimi_tanpopo/compare/v0.1.3...v0.2.0)
6
+
7
+ * Change `--pr-target-branch` and `--mr-target-branch` 's default value to repository's default branch
8
+ * https://github.com/sue445/sashimi_tanpopo/pull/53
9
+
4
10
  ## [0.1.3](https://github.com/sue445/sashimi_tanpopo/releases/tag/v0.1.3) - 2025-10-19
5
11
  [full changelog](http://github.com/sue445/sashimi_tanpopo/compare/v0.1.2...v0.1.3)
6
12
 
data/Dockerfile CHANGED
@@ -1,7 +1,7 @@
1
1
  ARG RUBY_VERSION=3.4
2
2
  FROM ruby:${RUBY_VERSION}-alpine
3
3
 
4
- ARG SASHIMI_TANPOPO_VERSION=0.1.2
4
+ ARG SASHIMI_TANPOPO_VERSION=0.1.3
5
5
 
6
6
  WORKDIR /work
7
7
 
data/README.md CHANGED
@@ -38,10 +38,18 @@ $ sashimi_tanpopo github --target-dir=/path/to/app --params=ruby_version:3.4.5 \
38
38
  ```
39
39
 
40
40
  ## Installation
41
+ ### Use gem directly
41
42
  ```bash
42
43
  gem install sashimi_tanpopo
43
44
  ```
44
45
 
46
+ ### Use via docker
47
+ e.g.
48
+
49
+ ```bash
50
+ docker run -v /path/to/recipe_dir:/recipes:ro -v $(pwd):/work --rm ghcr.io/sue445/sashimi_tanpopo <local|github|gitlab> <arguments> /recipes/recipe.rb
51
+ ```
52
+
45
53
  ## Usage
46
54
  ### sashimi_tanpopo local
47
55
  Change local files using recipe files
@@ -87,7 +95,7 @@ Options:
87
95
  --pr-title=PR_TITLE # Pull Request title
88
96
  [--pr-body=PR_BODY] # Pull Request body
89
97
  --pr-source-branch=pr_branch # Pull Request source branch (a.k.a. head branch)
90
- [--pr-target-branch=main] # Pull Request target branch (a.k.a. base branch). One of --pr-target-branch or $GITHUB_REF_NAME is required [$GITHUB_REF_NAME]
98
+ [--pr-target-branch=main] # Pull Request target branch (a.k.a. base branch). Default: default branch of repository (e.g. main, master)
91
99
  [--pr-assignees=one two three] # Pull Request assignees
92
100
  [--pr-reviewers=one two three] # Pull Request reviewers
93
101
  [--pr-labels=one two three] # Pull Request labels
@@ -95,6 +103,14 @@ Options:
95
103
  # Default: false
96
104
  ```
97
105
 
106
+ `--github-token` requires followings repository permissions
107
+
108
+ * Contents: Read and Write
109
+ * Pull requests: Read and Write
110
+ * Metadata: Read-only
111
+ * Workflows: Read and Write
112
+ * Only if you want to change `.github/workflows/*.yml`
113
+
98
114
  ### sashimi_tanpopo gitlab
99
115
  Change local files using recipe files and create Merge Request
100
116
 
@@ -121,7 +137,7 @@ Options:
121
137
  --mr-title=MR_TITLE # Merge Request title
122
138
  [--mr-body=MR_BODY] # Merge Request body
123
139
  --mr-source-branch=mr_branch # Merge Request source branch
124
- [--mr-target-branch=main] # Merge Request target branch). One of --mr-target-branch, $MR_TARGET_BRANCH or $CI_DEFAULT_BRANCH is required [$MR_TARGET_BRANCH, $CI_DEFAULT_BRANCH]
140
+ [--mr-target-branch=main] # Merge Request target branch. Default: default branch of project (e.g. main, master)
125
141
  [--mr-assignees=one two three] # Merge Request assignees
126
142
  [--mr-reviewers=one two three] # Merge Request reviewers
127
143
  [--mr-labels=one two three] # Merge Request labels
@@ -131,9 +147,18 @@ Options:
131
147
  # Default: false
132
148
  ```
133
149
 
150
+ `--gitlab-token` requires followings permissions
151
+
152
+ * Role: Developer
153
+ * Scopes: `api`
154
+
134
155
  ## Recipe file specification
135
156
  See [docs/RECIPE.md](docs/RECIPE.md)
136
157
 
158
+ ## Use on CI services
159
+ ### GitHub Actions
160
+ https://github.com/marketplace/actions/sashimi_tanpopo_action
161
+
137
162
  ## Development
138
163
 
139
164
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -44,7 +44,7 @@ module SashimiTanpopo
44
44
  option :pr_title, type: :string, desc: "Pull Request title", required: true
45
45
  option :pr_body, type: :string, desc: "Pull Request body"
46
46
  option :pr_source_branch, type: :string, desc: "Pull Request source branch (a.k.a. head branch)", required: true, banner: "pr_branch"
47
- option :pr_target_branch, type: :string, desc: "Pull Request target branch (a.k.a. base branch). One of --pr-target-branch or $GITHUB_REF_NAME is required [$GITHUB_REF_NAME]", banner: "main"
47
+ option :pr_target_branch, type: :string, desc: "Pull Request target branch (a.k.a. base branch). Default: default branch of repository (e.g. main, master)", banner: "main"
48
48
  option :pr_assignees, type: :array, desc: "Pull Request assignees", default: []
49
49
  option :pr_reviewers, type: :array, desc: "Pull Request reviewers", default: []
50
50
  option :pr_labels, type: :array, desc: "Pull Request labels", default: []
@@ -53,7 +53,6 @@ module SashimiTanpopo
53
53
  repository = option_or_env!(option_name: :github_repository, env_name: "GITHUB_REPOSITORY")
54
54
  api_endpoint = option_or_env!(option_name: :github_api_url, env_name: "GITHUB_API_URL")
55
55
  access_token = option_or_env!(option_name: :github_token, env_name: "GITHUB_TOKEN")
56
- pr_target_branch = option_or_env!(option_name: :pr_target_branch, env_name: "GITHUB_REF_NAME")
57
56
 
58
57
  Provider::GitHub.new(
59
58
  recipe_paths: recipe_files,
@@ -70,7 +69,7 @@ module SashimiTanpopo
70
69
  pr_title: options[:pr_title],
71
70
  pr_body: options[:pr_body],
72
71
  pr_source_branch: options[:pr_source_branch],
73
- pr_target_branch: pr_target_branch,
72
+ pr_target_branch: options[:pr_target_branch],
74
73
  pr_assignees: options[:pr_assignees],
75
74
  pr_reviewers: options[:pr_reviewers],
76
75
  pr_labels: options[:pr_labels],
@@ -89,7 +88,7 @@ module SashimiTanpopo
89
88
  option :mr_title, type: :string, desc: "Merge Request title", required: true
90
89
  option :mr_body, type: :string, desc: "Merge Request body"
91
90
  option :mr_source_branch, type: :string, desc: "Merge Request source branch", required: true, banner: "mr_branch"
92
- option :mr_target_branch, type: :string, desc: "Merge Request target branch). One of --mr-target-branch, $MR_TARGET_BRANCH or $CI_DEFAULT_BRANCH is required [$MR_TARGET_BRANCH, $CI_DEFAULT_BRANCH]", banner: "main"
91
+ option :mr_target_branch, type: :string, desc: "Merge Request target branch. Default: default branch of project (e.g. main, master)", banner: "main"
93
92
  option :mr_assignees, type: :array, desc: "Merge Request assignees", default: []
94
93
  option :mr_reviewers, type: :array, desc: "Merge Request reviewers", default: []
95
94
  option :mr_labels, type: :array, desc: "Merge Request labels", default: []
@@ -99,7 +98,6 @@ module SashimiTanpopo
99
98
  repository = option_or_env!(option_name: :gitlab_project, env_name: %w[GITLAB_PROJECT CI_PROJECT_PATH])
100
99
  api_endpoint = option_or_env!(option_name: :gitlab_api_url, env_name: %w[GITLAB_API_URL CI_API_V4_URL])
101
100
  access_token = option_or_env!(option_name: :gitlab_token, env_name: "GITLAB_TOKEN")
102
- mr_target_branch = option_or_env!(option_name: :mr_target_branch, env_name: %w[MR_TARGET_BRANCH CI_DEFAULT_BRANCH])
103
101
 
104
102
  Provider::GitLab.new(
105
103
  recipe_paths: recipe_files,
@@ -116,7 +114,7 @@ module SashimiTanpopo
116
114
  mr_title: options[:mr_title],
117
115
  mr_body: options[:mr_body],
118
116
  mr_source_branch: options[:mr_source_branch],
119
- mr_target_branch: mr_target_branch,
117
+ mr_target_branch: options[:mr_target_branch],
120
118
  mr_assignees: options[:mr_assignees],
121
119
  mr_reviewers: options[:mr_reviewers],
122
120
  mr_labels: options[:mr_labels],
@@ -22,7 +22,7 @@ module SashimiTanpopo
22
22
  # @param pr_title [String]
23
23
  # @param pr_body [String]
24
24
  # @param pr_source_branch [String] Pull Request source branch (a.k.a. head branch)
25
- # @param pr_target_branch [String] Pull Request target branch (a.k.a. base branch)
25
+ # @param pr_target_branch [String,nil] Pull Request target branch (a.k.a. base branch)
26
26
  # @param pr_assignees [Array<String>]
27
27
  # @param pr_reviewers [Array<String>]
28
28
  # @param pr_labels [Array<String>]
@@ -51,22 +51,11 @@ module SashimiTanpopo
51
51
  @pr_reviewers = pr_reviewers
52
52
  @pr_labels = pr_labels
53
53
  @is_draft_pr = is_draft_pr
54
+ @git_username = git_username
55
+ @git_email = git_email
56
+ @api_endpoint = api_endpoint
54
57
 
55
58
  @client = Octokit::Client.new(api_endpoint: api_endpoint, access_token: access_token)
56
-
57
- @git_username =
58
- if git_username
59
- git_username
60
- else
61
- current_user_name
62
- end
63
-
64
- @git_email =
65
- if git_email
66
- git_email
67
- else
68
- "#{@git_username}@users.noreply.#{self.class.github_host(api_endpoint)}"
69
- end
70
59
  end
71
60
 
72
61
  # Apply recipe files
@@ -110,6 +99,21 @@ module SashimiTanpopo
110
99
 
111
100
  private
112
101
 
102
+ # @return [String]
103
+ def pr_target_branch
104
+ @pr_target_branch ||= get_default_branch
105
+ end
106
+
107
+ # @return [String]
108
+ def git_username
109
+ @git_username ||= current_user_name
110
+ end
111
+
112
+ # @return [String]
113
+ def git_email
114
+ @git_email ||= "#{git_username}@users.noreply.#{self.class.github_host(@api_endpoint)}"
115
+ end
116
+
113
117
  # @return [String]
114
118
  #
115
119
  # @see https://docs.github.com/en/rest/users/users?apiVersion=2022-11-28#get-the-authenticated-user
@@ -117,6 +121,14 @@ module SashimiTanpopo
117
121
  @client.user[:login]
118
122
  end
119
123
 
124
+ # @return [String]
125
+ #
126
+ # @see https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#get-a-repository
127
+ def get_default_branch
128
+ res = @client.repository(@repository)
129
+ res[:default_branch]
130
+ end
131
+
120
132
  # Whether exists branch on repository
121
133
  #
122
134
  # @param branch [String]
@@ -140,7 +152,7 @@ module SashimiTanpopo
140
152
  # @see https://docs.github.com/en/rest/git/commits?apiVersion=2022-11-28#create-a-commit
141
153
  # @see https://docs.github.com/en/rest/git/refs?apiVersion=2022-11-28#update-a-reference
142
154
  def create_branch_and_push_changes(changed_files)
143
- current_ref = @client.ref(@repository, "heads/#{@pr_target_branch}")
155
+ current_ref = @client.ref(@repository, "heads/#{pr_target_branch}")
144
156
  branch_ref = @client.create_ref(@repository, "heads/#{@pr_source_branch}", current_ref.object.sha) # steep:ignore
145
157
 
146
158
  branch_commit = @client.commit(@repository, branch_ref.object.sha) # steep:ignore
@@ -157,8 +169,8 @@ module SashimiTanpopo
157
169
  tree.sha, # steep:ignore
158
170
  branch_ref.object.sha, # steep:ignore
159
171
  author: {
160
- name: @git_username,
161
- email: @git_email,
172
+ name: git_username,
173
+ email: git_email,
162
174
  }
163
175
  )
164
176
 
@@ -187,7 +199,7 @@ module SashimiTanpopo
187
199
  #
188
200
  # @see https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#create-a-pull-request
189
201
  def create_pull_request
190
- pr = @client.create_pull_request(@repository, @pr_target_branch, @pr_source_branch, @pr_title, @pr_body, draft: @is_draft_pr)
202
+ pr = @client.create_pull_request(@repository, pr_target_branch, @pr_source_branch, @pr_title, @pr_body, draft: @is_draft_pr)
191
203
 
192
204
  SashimiTanpopo.logger.info "Pull Request is created: #{pr[:html_url]}"
193
205
 
@@ -22,7 +22,7 @@ module SashimiTanpopo
22
22
  # @param mr_title [String]
23
23
  # @param mr_body [String]
24
24
  # @param mr_source_branch [String] Merge Request source branch
25
- # @param mr_target_branch [String] Merge Request target branch
25
+ # @param mr_target_branch [String,nil] Merge Request target branch
26
26
  # @param mr_assignees [Array<String>]
27
27
  # @param mr_reviewers [Array<String>]
28
28
  # @param mr_labels [Array<String>]
@@ -53,22 +53,11 @@ module SashimiTanpopo
53
53
  @mr_labels = mr_labels
54
54
  @is_draft_mr = is_draft_mr
55
55
  @is_auto_merge = is_auto_merge
56
+ @git_username = git_username
57
+ @git_email = git_email
58
+ @api_endpoint = api_endpoint
56
59
 
57
60
  @gitlab = Gitlab.client(endpoint: api_endpoint, private_token: access_token)
58
-
59
- @git_username =
60
- if git_username
61
- git_username
62
- else
63
- current_user_name
64
- end
65
-
66
- @git_email =
67
- if git_email
68
- git_email
69
- else
70
- "#{@git_username}@noreply.#{self.class.gitlab_host(api_endpoint)}"
71
- end
72
61
  end
73
62
 
74
63
  # Apply recipe files
@@ -161,6 +150,21 @@ module SashimiTanpopo
161
150
 
162
151
  private
163
152
 
153
+ # @return [String]
154
+ def mr_target_branch
155
+ @mr_target_branch ||= get_default_branch
156
+ end
157
+
158
+ # @return [String]
159
+ def git_username
160
+ @git_username ||= current_user_name
161
+ end
162
+
163
+ # @return [String]
164
+ def git_email
165
+ @git_email ||= "#{git_username}@noreply.#{self.class.gitlab_host(@api_endpoint)}"
166
+ end
167
+
164
168
  def with_retry
165
169
  retry_count ||= 0 # steep:ignore
166
170
 
@@ -189,6 +193,14 @@ module SashimiTanpopo
189
193
  user["username"]
190
194
  end
191
195
 
196
+ # @return [String]
197
+ def get_default_branch
198
+ project = with_retry do
199
+ @gitlab.project(@repository)
200
+ end
201
+ project["default_branch"]
202
+ end
203
+
192
204
  # Whether exists branch on repository
193
205
  #
194
206
  # @param branch [String]
@@ -226,9 +238,9 @@ module SashimiTanpopo
226
238
  @mr_source_branch,
227
239
  @commit_message,
228
240
  actions,
229
- start_branch: @mr_target_branch,
230
- author_email: @git_email,
231
- author_name: @git_username,
241
+ start_branch: mr_target_branch,
242
+ author_email: git_email,
243
+ author_name: git_username,
232
244
  )
233
245
  end
234
246
  end
@@ -239,7 +251,7 @@ module SashimiTanpopo
239
251
  def create_merge_request
240
252
  params = {
241
253
  source_branch: @mr_source_branch,
242
- target_branch: @mr_target_branch,
254
+ target_branch: mr_target_branch,
243
255
  remove_source_branch: true,
244
256
  description: @mr_body,
245
257
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SashimiTanpopo
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -17,6 +17,7 @@ module SashimiTanpopo
17
17
  @pr_labels: Array[String]
18
18
  @client: Octokit::Client
19
19
  @is_draft_pr: bool
20
+ @api_endpoint: String
20
21
 
21
22
  def initialize: (
22
23
  recipe_paths: Array[String],
@@ -33,7 +34,7 @@ module SashimiTanpopo
33
34
  pr_title: String,
34
35
  pr_body: String,
35
36
  pr_source_branch: String,
36
- pr_target_branch: String,
37
+ pr_target_branch: String?,
37
38
  ?pr_assignees: Array[String],
38
39
  ?pr_reviewers: Array[String],
39
40
  ?pr_labels: Array[String],
@@ -46,8 +47,16 @@ module SashimiTanpopo
46
47
 
47
48
  private
48
49
 
50
+ def pr_target_branch: () -> String
51
+
52
+ def git_username: () -> String
53
+
54
+ def git_email: () -> String
55
+
49
56
  def current_user_name: () -> String
50
57
 
58
+ def get_default_branch: () -> String
59
+
51
60
  def exists_branch?: (String branch) -> bool
52
61
 
53
62
  def create_branch_and_push_changes: (changed_files changed_files) -> void
@@ -18,6 +18,7 @@ module SashimiTanpopo
18
18
  @gitlab: Gitlab::Client
19
19
  @is_draft_mr: bool
20
20
  @is_auto_merge: bool
21
+ @api_endpoint: String
21
22
 
22
23
  def initialize: (
23
24
  recipe_paths: Array[String],
@@ -34,7 +35,7 @@ module SashimiTanpopo
34
35
  mr_title: String,
35
36
  mr_body: String,
36
37
  mr_source_branch: String,
37
- mr_target_branch: String,
38
+ mr_target_branch: String?,
38
39
  ?mr_assignees: Array[String],
39
40
  ?mr_reviewers: Array[String],
40
41
  ?mr_labels: Array[String],
@@ -56,10 +57,18 @@ module SashimiTanpopo
56
57
 
57
58
  private
58
59
 
60
+ def mr_target_branch: () -> String
61
+
62
+ def git_username: () -> String
63
+
64
+ def git_email: () -> String
65
+
59
66
  def with_retry: [T] { () -> T } -> T
60
67
 
61
68
  def current_user_name: () -> String
62
69
 
70
+ def get_default_branch: () -> String
71
+
63
72
  def exists_branch?: (String branch) -> bool
64
73
 
65
74
  def create_branch_and_push_changes: (Hash[String, { before_content: String, after_content: String, mode: String }] changed_files) -> void
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sashimi_tanpopo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445