Skip to content

Commit

Permalink
Add prefix to release tags in addition to suffix (#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitstart-app[bot] authored Jan 1, 2025
1 parent ca313d7 commit c366062
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 41 deletions.
2 changes: 2 additions & 0 deletions app/controllers/trains_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def train_params
:tag_platform_releases,
:notifications_enabled,
:tag_releases,
:tag_prefix,
:tag_suffix,
:patch_version_bump_only,
:approvals_enabled,
Expand Down Expand Up @@ -163,6 +164,7 @@ def train_update_params
:tag_platform_releases,
:notifications_enabled,
:tag_releases,
:tag_prefix,
:tag_suffix,
:patch_version_bump_only,
:approvals_enabled,
Expand Down

This file was deleted.

41 changes: 41 additions & 0 deletions app/javascript/controllers/string_affix_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {Controller} from "@hotwired/stimulus";

export default class extends Controller {
static values = {
baseString: String,
separator: { type: String, default: "-" },
commonPrefix: String,
}

static targets = [
"suffixInput",
"prefixInput",
"helpText",
]

initialize() {
this.__set();
}

set() {
this.__set();
}

__set() {
const prefix = this.prefixInputTarget.value;
const suffix = this.suffixInputTarget.value;
const baseString = this.baseStringValue;
const separator = this.separatorValue;
const commonPrefix = this.commonPrefixValue;

let result = `${commonPrefix}${baseString}`;
if (prefix) {
result = `${prefix}${separator}${result}`;
}
if (suffix) {
result = `${result}${separator}${suffix}`;
}

this.helpTextTarget.textContent = result;
}
}
1 change: 1 addition & 0 deletions app/models/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ def copy_approvals_allowed?

def base_tag_name
tag = "v#{release_version}"
tag = train.tag_prefix + "-" + tag if train.tag_prefix.present?
tag += "-hotfix" if hotfix?
tag += "-" + train.tag_suffix if train.tag_suffix.present?
tag
Expand Down
1 change: 1 addition & 0 deletions app/models/train.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# stop_automatic_releases_on_failure :boolean default(FALSE), not null
# tag_all_store_releases :boolean default(FALSE)
# tag_platform_releases :boolean default(FALSE)
# tag_prefix :string
# tag_releases :boolean default(TRUE)
# tag_suffix :string
# version_current :string
Expand Down
2 changes: 1 addition & 1 deletion app/views/trains/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
<%= f.with_advanced_section(heading: "Tag Your Releases") do |section| %>
<% section.with_description do %>
By default, a tag is created at the end of the release with the final version of the release.
You can turn off creation of tag. Or, you can add an optional suffix to your tags.
You can turn off creation of tag. Or, you can add an optional prefix or suffix to your tags.
<% end %>

<%= render partial: "release_tag_form", locals: { form: section.F } %>
Expand Down
20 changes: 12 additions & 8 deletions app/views/trains/_release_tag_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
hide_child: @train.tag_releases?) do |component| %>
<% component.with_child do %>
<section data-controller="help-text">
<div data-controller="domain--release-suffix-help"
data-domain--release-suffix-help-version-value="<%= @train.version_current || @train.version_seeded_with || "1.0.0" %>"
data-domain--release-suffix-help-version-suffix-current-value="<%= @train.tag_suffix %>"
data-domain--release-suffix-help-prefix-value="v">
<div data-controller="string-affix"
data-string-affix-base-string-value="<%= @train.version_current || @train.version_seeded_with || "1.0.0" %>"
data-string-affix-common-prefix-value="v">
<%= form.labeled_text_field :tag_prefix, "Tag prefix",
placeholder: "Eg., foo",
autocomplete: "off",
data: { string_affix_target: "prefixInput",
action: "string-affix#set" } %>
<%= form.labeled_text_field :tag_suffix, "Tag suffix",
placeholder: "Eg., nightly",
autocomplete: "off",
data: { domain__release_suffix_help_target: "input",
action: "domain--release-suffix-help#set" } %>
data: { string_affix_target: "suffixInput",
action: "string-affix#set" } %>
<div class="text-sm mt-1">
This is appended to the <strong>tag name</strong> of the release, as follows:&nbsp;
<span class="font-mono" data-domain--release-suffix-help-target="helpText"></span>
These are appended to the <strong>tag name</strong> of the release, as follows:&nbsp;
<span class="font-mono" data-string-affix-target="helpText"></span>
</div>
</div>
</section>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20241224064815_add_config_tag_prefix_to_train.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddConfigTagPrefixToTrain < ActiveRecord::Migration[7.2]
def change
add_column :trains, :tag_prefix, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/tasks/anonymize.rake
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace :anonymize do
whitelist "name", "slug", "description", "status", "branching_strategy", "version_seeded_with", "version_current",
"repeat_duration", "build_queue_wait_time", "build_queue_size", "backmerge_strategy", "manual_release",
"tag_platform_releases", "tag_all_store_releases", "compact_build_notes", "tag_releases", "build_queue_enabled",
"kickoff_at", "versioning_strategy", "send_build_notes", "notifications_enabled", "tag_suffix", "tag_platform_releases"
"kickoff_at", "versioning_strategy", "send_build_notes", "notifications_enabled", "tag_suffix", "tag_prefix", "tag_platform_releases"
whitelist_timestamps
anonymize("app_id") { |field| app.id }
anonymize("notification_channel") { |field| {"id" => "dummy", "name" => "test", "is_private" => false} }
Expand Down
1 change: 1 addition & 0 deletions spec/factories/trains.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
tag_platform_releases { false }
tag_all_store_releases { false }
tag_releases { true }
tag_prefix { nil }
tag_suffix { nil }
versioning_strategy { "semver" }
approvals_enabled { true }
Expand Down
65 changes: 65 additions & 0 deletions spec/models/release_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,71 @@
end
end

context "when tag prefix" do
let(:prefix) { "foo" }
let(:train) { create(:train, :active, tag_prefix: prefix) }

it "saves a new tag with the prefix + base name" do
allow_any_instance_of(GithubIntegration).to receive(:create_release!)

release.create_vcs_release!
expect(release.tag_name).to eq("#{prefix}-v1.2.3")
end

it "saves prefix + base name + last commit sha" do
raise_times(GithubIntegration, release_exists_error, :create_release!, 1)
commit = create(:commit, :without_trigger, release:)

release.create_vcs_release!
expect(release.tag_name).to eq("#{prefix}-v1.2.3-#{commit.short_sha}")
end

it "saves base prefix + name + last commit sha + time" do
raise_times(GithubIntegration, release_exists_error, :create_release!, 2)

freeze_time do
now = Time.now.to_i
commit = create(:commit, :without_trigger, release:)

release.create_vcs_release!
expect(release.tag_name).to eq("#{prefix}-v1.2.3-#{commit.short_sha}-#{now}")
end
end
end

context "when tag prefix and tag suffix" do
let(:prefix) { "foo" }
let(:suffix) { "nightly" }
let(:train) { create(:train, :active, tag_prefix: prefix, tag_suffix: suffix) }

it "saves a new tag with the prefix + base name + suffix" do
allow_any_instance_of(GithubIntegration).to receive(:create_release!)

release.create_vcs_release!
expect(release.tag_name).to eq("#{prefix}-v1.2.3-#{suffix}")
end

it "saves prefix + base name + suffix + last commit sha" do
raise_times(GithubIntegration, release_exists_error, :create_release!, 1)
commit = create(:commit, :without_trigger, release:)

release.create_vcs_release!
expect(release.tag_name).to eq("#{prefix}-v1.2.3-#{suffix}-#{commit.short_sha}")
end

it "saves base prefix + name + suffix + last commit sha + time" do
raise_times(GithubIntegration, release_exists_error, :create_release!, 2)

freeze_time do
now = Time.now.to_i
commit = create(:commit, :without_trigger, release:)

release.create_vcs_release!
expect(release.tag_name).to eq("#{prefix}-v1.2.3-#{suffix}-#{commit.short_sha}-#{now}")
end
end
end

context "when release tag disabled" do
let(:train) { create(:train, :active, tag_releases: false) }

Expand Down

0 comments on commit c366062

Please sign in to comment.