sashimi_tanpopo 0.1.3 → 0.3.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: 4cb5f08e4ea1b3f4a7dea92a3fc242ce77894fe0d6d610a48aab10e5b4bc3f99
4
+ data.tar.gz: ef6c01d72528207f0cad5961f894efbc38b885fdd0b425166245ac3c89c8fda4
5
5
  SHA512:
6
- metadata.gz: 96ef60917e18568424cfe95f741223bcc7a84c66878751d57b2838b1201ee55c53e1e1102c541d3f6864bfe1a14555ce4ca0e8f67938a51981c86298088eaf5b
7
- data.tar.gz: 8953c7816ff996d4bd32d30cecdcbdce5506102afff9a0284242631d1d23786c1d39e0f60875658c4031c03c4f17f9e169beecde1d1c72d40d9fd58077d88dc5
6
+ metadata.gz: 99ea3fc4cd53589883c574b56052a2c0147a5f238b698e748edd07330209cbcb84a49aeafbe7930ff9e29bb66f3859428eea9fffea2e719ddb283d7a7f96759b
7
+ data.tar.gz: 259c452fbeb224fa6b2c8a150429c028c6fff5f3d7c45659166d5de4a69ec9b6c058025be147fd75175f0d837b44bc86fc3a47f2dab5a5344be10de4710780e0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## [Unreleased]
2
- [full changelog](http://github.com/sue445/sashimi_tanpopo/compare/v0.1.3...main)
2
+ [full changelog](http://github.com/sue445/sashimi_tanpopo/compare/v0.3.0...main)
3
+
4
+ ## [0.3.0](https://github.com/sue445/sashimi_tanpopo/releases/tag/v0.3.0) - 2025-10-30
5
+ [full changelog](http://github.com/sue445/sashimi_tanpopo/compare/v0.2.0...v0.3.0)
6
+
7
+ * Support GitHub Actions Job Summary
8
+ * https://github.com/sue445/sashimi_tanpopo/pull/62
9
+
10
+ ## [0.2.0](https://github.com/sue445/sashimi_tanpopo/releases/tag/v0.2.0) - 2025-10-22
11
+ [full changelog](http://github.com/sue445/sashimi_tanpopo/compare/v0.1.3...v0.2.0)
12
+
13
+ * Change `--pr-target-branch` and `--mr-target-branch` 's default value to repository's default branch
14
+ * https://github.com/sue445/sashimi_tanpopo/pull/52
3
15
 
4
16
  ## [0.1.3](https://github.com/sue445/sashimi_tanpopo/releases/tag/v0.1.3) - 2025-10-19
5
17
  [full changelog](http://github.com/sue445/sashimi_tanpopo/compare/v0.1.2...v0.1.3)
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.2.0
5
5
 
6
6
  WORKDIR /work
7
7
 
data/README.md CHANGED
@@ -38,10 +38,20 @@ $ 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
+
53
+ c.f. https://github.com/sue445/sashimi_tanpopo/pkgs/container/sashimi_tanpopo
54
+
45
55
  ## Usage
46
56
  ### sashimi_tanpopo local
47
57
  Change local files using recipe files
@@ -62,7 +72,7 @@ Options:
62
72
  ```
63
73
 
64
74
  ### sashimi_tanpopo github
65
- Change local files using recipe files and create Pull Request
75
+ Change local files using recipe files and create Pull Request on GitHub
66
76
 
67
77
  ```bash
68
78
  $ sashimi_tanpopo help github
@@ -84,10 +94,11 @@ Options:
84
94
  [--github-api-url=GITHUB_API_URL] # GitHub API endpoint. One of --github-api-url or $GITHUB_API_URL is required [$GITHUB_API_URL]
85
95
  # Default: https://api.github.com
86
96
  [--github-token=GITHUB_TOKEN] # GitHub access token. One of --github-token or $GITHUB_TOKEN is required [$GITHUB_TOKEN]
97
+ [--github-step-summary=GITHUB_STEP_SUMMARY] # Path to GitHub step summary file [$GITHUB_STEP_SUMMARY]
87
98
  --pr-title=PR_TITLE # Pull Request title
88
99
  [--pr-body=PR_BODY] # Pull Request body
89
100
  --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]
101
+ [--pr-target-branch=main] # Pull Request target branch (a.k.a. base branch). Default: default branch of repository (e.g. main, master)
91
102
  [--pr-assignees=one two three] # Pull Request assignees
92
103
  [--pr-reviewers=one two three] # Pull Request reviewers
93
104
  [--pr-labels=one two three] # Pull Request labels
@@ -95,8 +106,18 @@ Options:
95
106
  # Default: false
96
107
  ```
97
108
 
109
+ `--github-token` requires followings repository permissions
110
+
111
+ * Contents: Read and Write
112
+ * Pull requests: Read and Write
113
+ * Metadata: Read-only
114
+ * Workflows: Read and Write
115
+ * Only if you want to change `.github/workflows/*.yml`
116
+
98
117
  ### sashimi_tanpopo gitlab
99
- Change local files using recipe files and create Merge Request
118
+ Change local files using recipe files and create Merge Request on [GitLab™](https://about.gitlab.com/)
119
+
120
+ _GITLAB is a trademark of GitLab Inc. in the United States and other countries and regions_
100
121
 
101
122
  ```bash
102
123
  $ sashimi_tanpopo help gitlab
@@ -121,7 +142,7 @@ Options:
121
142
  --mr-title=MR_TITLE # Merge Request title
122
143
  [--mr-body=MR_BODY] # Merge Request body
123
144
  --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]
145
+ [--mr-target-branch=main] # Merge Request target branch. Default: default branch of project (e.g. main, master)
125
146
  [--mr-assignees=one two three] # Merge Request assignees
126
147
  [--mr-reviewers=one two three] # Merge Request reviewers
127
148
  [--mr-labels=one two three] # Merge Request labels
@@ -131,9 +152,29 @@ Options:
131
152
  # Default: false
132
153
  ```
133
154
 
155
+ `--gitlab-token` requires followings permissions
156
+
157
+ * Role: Developer
158
+ * Scopes: `api`
159
+
134
160
  ## Recipe file specification
135
161
  See [docs/RECIPE.md](docs/RECIPE.md)
136
162
 
163
+ ## Use on CI services
164
+ ### GitHub Actions
165
+ See https://github.com/marketplace/actions/sashimi_tanpopo_action
166
+
167
+ ### GitLab CI
168
+ See https://gitlab.com/explore/catalog/sue445/sashimi_tanpopo-components
169
+
170
+ ## Real example
171
+ sashimi_tanpopo is used to manage configuration files for my multiple personal repositories.
172
+
173
+ See followings.
174
+
175
+ * https://github.com/sue445/sashimi_tanpopo-personal
176
+ * https://gitlab.com/sue445/sashimi_tanpopo-personal-gitlab
177
+
137
178
  ## Development
138
179
 
139
180
  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.
data/docs/RECIPE.md CHANGED
@@ -2,6 +2,7 @@
2
2
  Recipe file is simple Ruby script, with some exceptions.
3
3
 
4
4
  By avoiding the DSL methods listed below, you are free to write code as you like.
5
+ (e.g. write your cool code, define variables, require other files)
5
6
 
6
7
  ## Special methods available within recipe file
7
8
  The following methods are special variables available within recipe file.
@@ -35,25 +35,27 @@ module SashimiTanpopo
35
35
 
36
36
  desc "github RECIPE [RECIPE...]", "Change local files using recipe files and create Pull Request"
37
37
  define_exec_common_options
38
- option :git_user_name, type: :string, desc: "user name for git commit. Default: username of user authenticated with token"
39
- option :git_email, type: :string, desc: "email for git commit. Default: <git_user_name>@users.noreply.<github_host>"
40
- option :message, type: :string, desc: "commit message", required: true, aliases: "-m", banner: "COMMIT_MESSAGE"
41
- option :github_repository, type: :string, desc: "GitHub repository for Pull Request. One of --github--repository or $GITHUB_REPOSITORY is required [$GITHUB_REPOSITORY]", banner: "user/repo"
42
- option :github_api_url, type: :string, desc: "GitHub API endpoint. One of --github-api-url or $GITHUB_API_URL is required [$GITHUB_API_URL]", default: "https://api.github.com"
43
- option :github_token, type: :string, desc: "GitHub access token. One of --github-token or $GITHUB_TOKEN is required [$GITHUB_TOKEN]"
44
- option :pr_title, type: :string, desc: "Pull Request title", required: true
45
- option :pr_body, type: :string, desc: "Pull Request body"
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"
48
- option :pr_assignees, type: :array, desc: "Pull Request assignees", default: []
49
- option :pr_reviewers, type: :array, desc: "Pull Request reviewers", default: []
50
- option :pr_labels, type: :array, desc: "Pull Request labels", default: []
51
- option :pr_draft, type: :boolean, desc: "Whether to create draft Pull Request", default: false
38
+ option :git_user_name, type: :string, desc: "user name for git commit. Default: username of user authenticated with token"
39
+ option :git_email, type: :string, desc: "email for git commit. Default: <git_user_name>@users.noreply.<github_host>"
40
+ option :message, type: :string, desc: "commit message", required: true, aliases: "-m", banner: "COMMIT_MESSAGE"
41
+ option :github_repository, type: :string, desc: "GitHub repository for Pull Request. One of --github--repository or $GITHUB_REPOSITORY is required [$GITHUB_REPOSITORY]", banner: "user/repo"
42
+ option :github_api_url, type: :string, desc: "GitHub API endpoint. One of --github-api-url or $GITHUB_API_URL is required [$GITHUB_API_URL]", default: "https://api.github.com"
43
+ option :github_token, type: :string, desc: "GitHub access token. One of --github-token or $GITHUB_TOKEN is required [$GITHUB_TOKEN]"
44
+ option :github_step_summary, type: :string, desc: "Path to GitHub step summary file [$GITHUB_STEP_SUMMARY]"
45
+ option :pr_title, type: :string, desc: "Pull Request title", required: true
46
+ option :pr_body, type: :string, desc: "Pull Request body"
47
+ option :pr_source_branch, type: :string, desc: "Pull Request source branch (a.k.a. head branch)", required: true, banner: "pr_branch"
48
+ 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"
49
+ option :pr_assignees, type: :array, desc: "Pull Request assignees", default: []
50
+ option :pr_reviewers, type: :array, desc: "Pull Request reviewers", default: []
51
+ option :pr_labels, type: :array, desc: "Pull Request labels", default: []
52
+ option :pr_draft, type: :boolean, desc: "Whether to create draft Pull Request", default: false
52
53
  def github(*recipe_files)
53
54
  repository = option_or_env!(option_name: :github_repository, env_name: "GITHUB_REPOSITORY")
54
55
  api_endpoint = option_or_env!(option_name: :github_api_url, env_name: "GITHUB_API_URL")
55
56
  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
+
58
+ summary_path = option_or_env(option_name: :github_step_summary, env_name: "GITHUB_STEP_SUMMARY")
57
59
 
58
60
  Provider::GitHub.new(
59
61
  recipe_paths: recipe_files,
@@ -70,11 +72,12 @@ module SashimiTanpopo
70
72
  pr_title: options[:pr_title],
71
73
  pr_body: options[:pr_body],
72
74
  pr_source_branch: options[:pr_source_branch],
73
- pr_target_branch: pr_target_branch,
75
+ pr_target_branch: options[:pr_target_branch],
74
76
  pr_assignees: options[:pr_assignees],
75
77
  pr_reviewers: options[:pr_reviewers],
76
78
  pr_labels: options[:pr_labels],
77
79
  is_draft_pr: options[:pr_draft],
80
+ summary_path: summary_path,
78
81
  ).perform
79
82
  end
80
83
 
@@ -89,7 +92,7 @@ module SashimiTanpopo
89
92
  option :mr_title, type: :string, desc: "Merge Request title", required: true
90
93
  option :mr_body, type: :string, desc: "Merge Request body"
91
94
  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"
95
+ option :mr_target_branch, type: :string, desc: "Merge Request target branch. Default: default branch of project (e.g. main, master)", banner: "main"
93
96
  option :mr_assignees, type: :array, desc: "Merge Request assignees", default: []
94
97
  option :mr_reviewers, type: :array, desc: "Merge Request reviewers", default: []
95
98
  option :mr_labels, type: :array, desc: "Merge Request labels", default: []
@@ -99,7 +102,6 @@ module SashimiTanpopo
99
102
  repository = option_or_env!(option_name: :gitlab_project, env_name: %w[GITLAB_PROJECT CI_PROJECT_PATH])
100
103
  api_endpoint = option_or_env!(option_name: :gitlab_api_url, env_name: %w[GITLAB_API_URL CI_API_V4_URL])
101
104
  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
105
 
104
106
  Provider::GitLab.new(
105
107
  recipe_paths: recipe_files,
@@ -116,7 +118,7 @@ module SashimiTanpopo
116
118
  mr_title: options[:mr_title],
117
119
  mr_body: options[:mr_body],
118
120
  mr_source_branch: options[:mr_source_branch],
119
- mr_target_branch: mr_target_branch,
121
+ mr_target_branch: options[:mr_target_branch],
120
122
  mr_assignees: options[:mr_assignees],
121
123
  mr_reviewers: options[:mr_reviewers],
122
124
  mr_labels: options[:mr_labels],
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SashimiTanpopo
4
+ module DiffHelper
5
+ # Generate diff between 2 strings
6
+ #
7
+ # @param str1 [String]
8
+ # @param str2 [String]
9
+ # @param is_colored [Boolean]
10
+ #
11
+ # @return [String]
12
+ def self.generate_diff(str1, str2, is_colored:)
13
+ format = is_colored ? :color : :text
14
+ Diffy::Diff.new(str1, str2, context: 3).to_s(format)
15
+ end
16
+ end
17
+ end
@@ -70,8 +70,7 @@ module SashimiTanpopo
70
70
  @__dry_run__ = dry_run
71
71
  @__target_dir__ = target_dir
72
72
  @__is_update_local__ = is_update_local
73
-
74
- @__diffy_format__ = is_colored ? :color : :text
73
+ @__is_colored__ = is_colored
75
74
  end
76
75
 
77
76
  # passed from `--params`
@@ -177,7 +176,7 @@ module SashimiTanpopo
177
176
  # @param str1 [String]
178
177
  # @param str2 [String]
179
178
  def show_diff(str1, str2)
180
- diff_text = Diffy::Diff.new(str1, str2, context: 3).to_s(@__diffy_format__) # steep:ignore
179
+ diff_text = DiffHelper.generate_diff(str1, str2, is_colored: @__is_colored__)
181
180
 
182
181
  SashimiTanpopo.logger.info "diff:"
183
182
 
@@ -22,16 +22,18 @@ 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>]
29
29
  # @param is_draft_pr [Boolean] Whether create draft Pull Request
30
+ # @param summary_path [String,nil]
30
31
  def initialize(recipe_paths:, target_dir:, params:, dry_run:, is_colored:,
31
32
  git_username:, git_email:, commit_message:,
32
33
  repository:, access_token:, api_endpoint: DEFAULT_API_ENDPOINT,
33
34
  pr_title:, pr_body:, pr_source_branch:, pr_target_branch:,
34
- pr_assignees: [], pr_reviewers: [], pr_labels: [], is_draft_pr:)
35
+ pr_assignees: [], pr_reviewers: [], pr_labels: [], is_draft_pr:,
36
+ summary_path:)
35
37
  super(
36
38
  recipe_paths: recipe_paths,
37
39
  target_dir: target_dir,
@@ -51,22 +53,12 @@ module SashimiTanpopo
51
53
  @pr_reviewers = pr_reviewers
52
54
  @pr_labels = pr_labels
53
55
  @is_draft_pr = is_draft_pr
56
+ @git_username = git_username
57
+ @git_email = git_email
58
+ @api_endpoint = api_endpoint
59
+ @summary_path = summary_path || ""
54
60
 
55
61
  @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
62
  end
71
63
 
72
64
  # Apply recipe files
@@ -76,6 +68,8 @@ module SashimiTanpopo
76
68
  def perform
77
69
  changed_files = apply_recipe_files
78
70
 
71
+ write_summary_file(changed_files)
72
+
79
73
  return nil if changed_files.empty? || @dry_run
80
74
 
81
75
  if exists_branch?(@pr_source_branch)
@@ -108,8 +102,53 @@ module SashimiTanpopo
108
102
  DEFAULT_GITHUB_HOST
109
103
  end
110
104
 
105
+ # @param changed_files [Hash<String, { before_content: String, after_content: String, mode: String }>] key: f path, value: Hash
106
+ # @param dry_run [Boolean]
107
+ #
108
+ # @return [String]
109
+ def self.generate_summary(changed_files:, dry_run:)
110
+ header = +"## :page_facing_up: sashimi_tanpopo report"
111
+ header << " (dry run)" if dry_run
112
+
113
+ lines = [header]
114
+
115
+ if changed_files.empty?
116
+ lines.push(
117
+ "no changes",
118
+ "",
119
+ )
120
+ else
121
+ changed_files.each do |path, data|
122
+ lines.push(
123
+ "### :memo: #{path}",
124
+ "```diff",
125
+ SashimiTanpopo::DiffHelper.generate_diff(data[:before_content], data[:after_content], is_colored: false).rstrip,
126
+ "```",
127
+ "",
128
+ )
129
+ end
130
+ end
131
+
132
+ lines.join("\n")
133
+ end
134
+
111
135
  private
112
136
 
137
+ # @return [String]
138
+ def pr_target_branch
139
+ @pr_target_branch ||= get_default_branch
140
+ end
141
+
142
+ # @return [String]
143
+ def git_username
144
+ @git_username ||= current_user_name
145
+ end
146
+
147
+ # @return [String]
148
+ def git_email
149
+ @git_email ||= "#{git_username}@users.noreply.#{self.class.github_host(@api_endpoint)}"
150
+ end
151
+
113
152
  # @return [String]
114
153
  #
115
154
  # @see https://docs.github.com/en/rest/users/users?apiVersion=2022-11-28#get-the-authenticated-user
@@ -117,6 +156,30 @@ module SashimiTanpopo
117
156
  @client.user[:login]
118
157
  end
119
158
 
159
+ # @return [String]
160
+ #
161
+ # @see https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#get-a-repository
162
+ def get_default_branch
163
+ res = @client.repository(@repository)
164
+ res[:default_branch]
165
+ end
166
+
167
+ # @param changed_files [Hash<String, { before_content: String, after_content: String, mode: String }>] key: f path, value: Hash
168
+ def write_summary_file(changed_files)
169
+ return if @summary_path.empty?
170
+
171
+ unless File.exist?(@summary_path)
172
+ SashimiTanpopo.logger.warn "#{@summary_path} does not exist"
173
+ return
174
+ end
175
+
176
+ summary = self.class.generate_summary(changed_files: changed_files, dry_run: @dry_run)
177
+
178
+ File.open(@summary_path, "a") do |f|
179
+ f.write(summary)
180
+ end
181
+ end
182
+
120
183
  # Whether exists branch on repository
121
184
  #
122
185
  # @param branch [String]
@@ -140,7 +203,7 @@ module SashimiTanpopo
140
203
  # @see https://docs.github.com/en/rest/git/commits?apiVersion=2022-11-28#create-a-commit
141
204
  # @see https://docs.github.com/en/rest/git/refs?apiVersion=2022-11-28#update-a-reference
142
205
  def create_branch_and_push_changes(changed_files)
143
- current_ref = @client.ref(@repository, "heads/#{@pr_target_branch}")
206
+ current_ref = @client.ref(@repository, "heads/#{pr_target_branch}")
144
207
  branch_ref = @client.create_ref(@repository, "heads/#{@pr_source_branch}", current_ref.object.sha) # steep:ignore
145
208
 
146
209
  branch_commit = @client.commit(@repository, branch_ref.object.sha) # steep:ignore
@@ -157,8 +220,8 @@ module SashimiTanpopo
157
220
  tree.sha, # steep:ignore
158
221
  branch_ref.object.sha, # steep:ignore
159
222
  author: {
160
- name: @git_username,
161
- email: @git_email,
223
+ name: git_username,
224
+ email: git_email,
162
225
  }
163
226
  )
164
227
 
@@ -187,7 +250,7 @@ module SashimiTanpopo
187
250
  #
188
251
  # @see https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#create-a-pull-request
189
252
  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)
253
+ pr = @client.create_pull_request(@repository, pr_target_branch, @pr_source_branch, @pr_title, @pr_body, draft: @is_draft_pr)
191
254
 
192
255
  SashimiTanpopo.logger.info "Pull Request is created: #{pr[:html_url]}"
193
256
 
@@ -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.3.0"
5
5
  end
@@ -10,6 +10,7 @@ require_relative "sashimi_tanpopo/version"
10
10
  require_relative "sashimi_tanpopo/dsl"
11
11
  require_relative "sashimi_tanpopo/logger"
12
12
  require_relative "sashimi_tanpopo/provider"
13
+ require_relative "sashimi_tanpopo/diff_helper"
13
14
 
14
15
  module SashimiTanpopo
15
16
  class Error < StandardError; end
@@ -6,7 +6,7 @@ gems:
6
6
  source:
7
7
  type: git
8
8
  name: ruby/gem_rbs_collection
9
- revision: 10d80b1f45dd4241d64d40b49e622cd5d3cfa903
9
+ revision: 533a74999571ba71d84cbbb3ef47ba34de526a12
10
10
  remote: https://github.com/ruby/gem_rbs_collection.git
11
11
  repo_dir: gems
12
12
  - name: base64
@@ -14,7 +14,7 @@ gems:
14
14
  source:
15
15
  type: git
16
16
  name: ruby/gem_rbs_collection
17
- revision: 10d80b1f45dd4241d64d40b49e622cd5d3cfa903
17
+ revision: 533a74999571ba71d84cbbb3ef47ba34de526a12
18
18
  remote: https://github.com/ruby/gem_rbs_collection.git
19
19
  repo_dir: gems
20
20
  - name: bigdecimal
@@ -22,7 +22,7 @@ gems:
22
22
  source:
23
23
  type: git
24
24
  name: ruby/gem_rbs_collection
25
- revision: 10d80b1f45dd4241d64d40b49e622cd5d3cfa903
25
+ revision: 533a74999571ba71d84cbbb3ef47ba34de526a12
26
26
  remote: https://github.com/ruby/gem_rbs_collection.git
27
27
  repo_dir: gems
28
28
  - name: csv
@@ -30,7 +30,7 @@ gems:
30
30
  source:
31
31
  type: git
32
32
  name: ruby/gem_rbs_collection
33
- revision: 10d80b1f45dd4241d64d40b49e622cd5d3cfa903
33
+ revision: 533a74999571ba71d84cbbb3ef47ba34de526a12
34
34
  remote: https://github.com/ruby/gem_rbs_collection.git
35
35
  repo_dir: gems
36
36
  - name: date
@@ -46,7 +46,15 @@ gems:
46
46
  source:
47
47
  type: git
48
48
  name: ruby/gem_rbs_collection
49
- revision: 10d80b1f45dd4241d64d40b49e622cd5d3cfa903
49
+ revision: 533a74999571ba71d84cbbb3ef47ba34de526a12
50
+ remote: https://github.com/ruby/gem_rbs_collection.git
51
+ repo_dir: gems
52
+ - name: diffy
53
+ version: '3.4'
54
+ source:
55
+ type: git
56
+ name: ruby/gem_rbs_collection
57
+ revision: 533a74999571ba71d84cbbb3ef47ba34de526a12
50
58
  remote: https://github.com/ruby/gem_rbs_collection.git
51
59
  repo_dir: gems
52
60
  - name: erb
@@ -58,7 +66,7 @@ gems:
58
66
  source:
59
67
  type: git
60
68
  name: ruby/gem_rbs_collection
61
- revision: 10d80b1f45dd4241d64d40b49e622cd5d3cfa903
69
+ revision: 533a74999571ba71d84cbbb3ef47ba34de526a12
62
70
  remote: https://github.com/ruby/gem_rbs_collection.git
63
71
  repo_dir: gems
64
72
  - name: fileutils
@@ -69,12 +77,20 @@ gems:
69
77
  version: '0'
70
78
  source:
71
79
  type: stdlib
80
+ - name: gitlab
81
+ version: '6.0'
82
+ source:
83
+ type: git
84
+ name: ruby/gem_rbs_collection
85
+ revision: 533a74999571ba71d84cbbb3ef47ba34de526a12
86
+ remote: https://github.com/ruby/gem_rbs_collection.git
87
+ repo_dir: gems
72
88
  - name: hashdiff
73
89
  version: '1.1'
74
90
  source:
75
91
  type: git
76
92
  name: ruby/gem_rbs_collection
77
- revision: 10d80b1f45dd4241d64d40b49e622cd5d3cfa903
93
+ revision: 533a74999571ba71d84cbbb3ef47ba34de526a12
78
94
  remote: https://github.com/ruby/gem_rbs_collection.git
79
95
  repo_dir: gems
80
96
  - name: httparty
@@ -82,7 +98,7 @@ gems:
82
98
  source:
83
99
  type: git
84
100
  name: ruby/gem_rbs_collection
85
- revision: 10d80b1f45dd4241d64d40b49e622cd5d3cfa903
101
+ revision: 533a74999571ba71d84cbbb3ef47ba34de526a12
86
102
  remote: https://github.com/ruby/gem_rbs_collection.git
87
103
  repo_dir: gems
88
104
  - name: io-console
@@ -102,7 +118,7 @@ gems:
102
118
  source:
103
119
  type: git
104
120
  name: ruby/gem_rbs_collection
105
- revision: 10d80b1f45dd4241d64d40b49e622cd5d3cfa903
121
+ revision: 533a74999571ba71d84cbbb3ef47ba34de526a12
106
122
  remote: https://github.com/ruby/gem_rbs_collection.git
107
123
  repo_dir: gems
108
124
  - name: monitor
@@ -122,7 +138,7 @@ gems:
122
138
  source:
123
139
  type: git
124
140
  name: ruby/gem_rbs_collection
125
- revision: 10d80b1f45dd4241d64d40b49e622cd5d3cfa903
141
+ revision: 533a74999571ba71d84cbbb3ef47ba34de526a12
126
142
  remote: https://github.com/ruby/gem_rbs_collection.git
127
143
  repo_dir: gems
128
144
  - name: parallel
@@ -130,7 +146,7 @@ gems:
130
146
  source:
131
147
  type: git
132
148
  name: ruby/gem_rbs_collection
133
- revision: 10d80b1f45dd4241d64d40b49e622cd5d3cfa903
149
+ revision: 533a74999571ba71d84cbbb3ef47ba34de526a12
134
150
  remote: https://github.com/ruby/gem_rbs_collection.git
135
151
  repo_dir: gems
136
152
  - name: pp
@@ -154,7 +170,7 @@ gems:
154
170
  source:
155
171
  type: git
156
172
  name: ruby/gem_rbs_collection
157
- revision: 10d80b1f45dd4241d64d40b49e622cd5d3cfa903
173
+ revision: 533a74999571ba71d84cbbb3ef47ba34de526a12
158
174
  remote: https://github.com/ruby/gem_rbs_collection.git
159
175
  repo_dir: gems
160
176
  - name: rdoc
@@ -170,7 +186,7 @@ gems:
170
186
  source:
171
187
  type: git
172
188
  name: ruby/gem_rbs_collection
173
- revision: 10d80b1f45dd4241d64d40b49e622cd5d3cfa903
189
+ revision: 533a74999571ba71d84cbbb3ef47ba34de526a12
174
190
  remote: https://github.com/ruby/gem_rbs_collection.git
175
191
  repo_dir: gems
176
192
  - name: timeout
@@ -190,7 +206,7 @@ gems:
190
206
  source:
191
207
  type: git
192
208
  name: ruby/gem_rbs_collection
193
- revision: 10d80b1f45dd4241d64d40b49e622cd5d3cfa903
209
+ revision: 533a74999571ba71d84cbbb3ef47ba34de526a12
194
210
  remote: https://github.com/ruby/gem_rbs_collection.git
195
211
  repo_dir: gems
196
212
  gemfile_lock_path: Gemfile.lock
@@ -0,0 +1,5 @@
1
+ module SashimiTanpopo
2
+ module DiffHelper
3
+ def self.generate_diff: (String str1, String str2, is_colored: bool) -> String
4
+ end
5
+ end
@@ -24,7 +24,7 @@ module SashimiTanpopo
24
24
  @__dry_run__: bool
25
25
  @__target_dir__: String
26
26
  @__is_update_local__: bool
27
- @__diffy_format__: Symbol
27
+ @__is_colored__: bool
28
28
  @__changed_files__: changed_files
29
29
 
30
30
  def initialize: (
@@ -17,6 +17,8 @@ module SashimiTanpopo
17
17
  @pr_labels: Array[String]
18
18
  @client: Octokit::Client
19
19
  @is_draft_pr: bool
20
+ @api_endpoint: String
21
+ @summary_path: String
20
22
 
21
23
  def initialize: (
22
24
  recipe_paths: Array[String],
@@ -33,21 +35,34 @@ module SashimiTanpopo
33
35
  pr_title: String,
34
36
  pr_body: String,
35
37
  pr_source_branch: String,
36
- pr_target_branch: String,
38
+ pr_target_branch: String?,
37
39
  ?pr_assignees: Array[String],
38
40
  ?pr_reviewers: Array[String],
39
41
  ?pr_labels: Array[String],
40
42
  is_draft_pr: bool,
43
+ summary_path: String?
41
44
  ) -> void
42
45
 
43
46
  def perform: () -> String?
44
47
 
45
48
  def self.github_host: (String api_endpoint) -> String
46
49
 
50
+ def self.generate_summary: (changed_files: changed_files, dry_run: bool) -> String
51
+
47
52
  private
48
53
 
54
+ def pr_target_branch: () -> String
55
+
56
+ def git_username: () -> String
57
+
58
+ def git_email: () -> String
59
+
49
60
  def current_user_name: () -> String
50
61
 
62
+ def get_default_branch: () -> String
63
+
64
+ def write_summary_file: (changed_files changed_files) -> void
65
+
51
66
  def exists_branch?: (String branch) -> bool
52
67
 
53
68
  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.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445
@@ -261,6 +261,7 @@ files:
261
261
  - exe/sashimi_tanpopo
262
262
  - lib/sashimi_tanpopo.rb
263
263
  - lib/sashimi_tanpopo/cli.rb
264
+ - lib/sashimi_tanpopo/diff_helper.rb
264
265
  - lib/sashimi_tanpopo/dsl.rb
265
266
  - lib/sashimi_tanpopo/logger.rb
266
267
  - lib/sashimi_tanpopo/provider.rb
@@ -273,6 +274,7 @@ files:
273
274
  - rbs_collection.yaml
274
275
  - sig/sashimi_tanpopo.rbs
275
276
  - sig/sashimi_tanpopo/cli.rbs
277
+ - sig/sashimi_tanpopo/diff_helper.rbs
276
278
  - sig/sashimi_tanpopo/dsl.rbs
277
279
  - sig/sashimi_tanpopo/logger.rbs
278
280
  - sig/sashimi_tanpopo/provider/base.rbs