diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..a59bebb --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,17 @@ +name: Test + +on: push + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: redmine-plugin-test-action + uses: two-pack/redmine-plugin-test-action@v2.0.2 + with: + plugin_name: redmine_serial_number_field + redmine_version: v4.1 + ruby_version: v2.6 + database: postgresql + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 17b1cda..0000000 --- a/.travis.yml +++ /dev/null @@ -1,34 +0,0 @@ - -language: ruby - -rvm: - - 2.2 - - 2.3 - - 2.4 - - 2.5 - - 2.6 - -env: - - REDMINE_REPOS=branches/4.0-stable - -before_install: - - export PLUGIN_NAME=redmine_serial_number_field - - export DB=sqlite - - export NOKOGIRI_USE_SYSTEM_LIBRARIES=true - - export REDMINE_PATH=$HOME/redmine - - export BUNDLE_GEMFILE=$REDMINE_PATH/Gemfile - - svn co http://svn.redmine.org/redmine/$REDMINE_REPOS $REDMINE_PATH - - ln -s $TRAVIS_BUILD_DIR $REDMINE_PATH/plugins/$PLUGIN_NAME - - cp test/database.travis.yml $REDMINE_PATH/config/database.yml - - cd $REDMINE_PATH - - bundle update - -before_script: - - bundle exec rails db:migrate - -script: - - bundle exec rails redmine:plugins:test NAME=$PLUGIN_NAME RAILS_ENV=test - -branches: - only: - - master diff --git a/CHANGELOG.md b/CHANGELOG.md index 3911c18..c49330e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## 3.0.0 + +- Added ISO format #8 (@rambowm) +- Dropped Redmine 4.0 support +- Redmine 4.1 support +- Fixed automatic serial number when copying issue + - チケットコピー時に自動採番されない #6 (@subaru019) + - [Review comments for this plugin on redmine.org](https://www.redmine.org/plugins/redmine_serial_number_field) (Jorge Garcia, Quan VN, qn wang) + ## 2.0.0 - Support Redmine 4.0 (@nanego) diff --git a/README.en.md b/README.en.md index 234db5b..206687e 100644 --- a/README.en.md +++ b/README.en.md @@ -1,7 +1,5 @@ # Redmine Serial Number Field -[![Build Status](https://travis-ci.org/matsukei/redmine_serial_number_field.svg?branch=master)](https://travis-ci.org/matsukei/redmine_serial_number_field) - [日本語 »](https://github.com/matsukei/redmine_serial_number_field/blob/master/README.md) Add a format to be serial number in the specified format as a issue custom field. @@ -50,16 +48,17 @@ Add a format to be serial number in the specified format as a issue custom field ## Supported versions -* Redmine 4.0 (Ruby 2.2, 2.3, 2.4, 2.5, 2.6) +* Redmine 4.1 (Ruby 2.6) ## Format specifications -|Column used in year format |Year format|fiscal year(4/1 - 3/31)|Serial number format| result | -|---------------------------|-----------|-----------|--------------------|------------------------| -|Issue#created_on |`yy` |No |000 |2015-03-01 => '15001' | -|Issue#created_on |`yyyy` |No |0000 |2015-03-01 => '20150001'| -|Issue#created_on |`YY` |Yes |000 |2015-03-01 => '14001' | -|Issue#created_on |`YYYY` |Yes |0000 |2015-03-01 => '20140001'| +|Column used in year format |Year format|fiscal year(4/1 - 3/31)|e.g. Regular expression |e.g Result (2015-03-31)| +|---------------------------|-----------|-----------------------|-------------------------|-----------------------| +|Issue#created_on |`yyyy` |No |`{yyyy}-{0000}` |`2015-0001` | +|^ |`yy` |No |`{yy}-{0000}` |`15-0001` | +|^ |`YYYY` |Yes |`{YYYY}-{0000}` |`2014-0001` | +|^ |`YY` |Yes |`{YY}-{0000}` |`14-0001` | +|^ |`ISO` |No |`{ISO}-{0000}` |`20150331-0001` | * OK * `{000000}` #=> `000001` diff --git a/README.md b/README.md index 318093d..6475a5b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # Redmine Serial Number Field -[![Build Status](https://travis-ci.org/matsukei/redmine_serial_number_field.svg?branch=master)](https://travis-ci.org/matsukei/redmine_serial_number_field) - [English »](https://github.com/matsukei/redmine_serial_number_field/blob/master/README.en.md) Redmine に自動で連番を付加するカスタムフィールドを提供するプラグインです。 @@ -11,7 +9,7 @@ Redmine に自動で連番を付加するカスタムフィールドを提供す * チケットに対するカスタムフィールドの書式として「自動採番」が利用可能になります。 * カスタムフィールドの新規作成後は、正規表現を編集することは、できません。 * チケットが登録できる、全てのユーザーは、自動採番の権限があります。 -* 指定したフォーマットの連番を、チケット登録や更新時(一括操作も含む)に自動的に採番します。 +* 指定した正規表現に基づいて、チケット登録や更新時(一括操作も含む)に自動的に採番します。 * カスタムフィールド単位での採番となります。同じカスタムフィールドを複数のプロジェクトで使用している場合は、それらのプロジェクトで連続した採番になります。 * カスタムフィールド項目は、チケットの閲覧時には表示します。しかし、登録および更新時には表示しません。 * チケットのフィルタ条件、検索対象など、カスタムフィールドの基本的なオプションも利用可能です。 @@ -31,7 +29,7 @@ Redmine に自動で連番を付加するカスタムフィールドを提供す 1. チケットの新しいカスタムフィールドを作成します。 2. 項目「書式」を自動採番に変更します。 -3. 項目「正規表現」に連番フォーマットを指定します。 +3. 項目「正規表現」に年表記書式や連番書式を指定します。 4. フィルタや検索条件として使いたい場合は、適宜チェックを入れます。 5. 自動採番をしたいトラッカーとプロジェクトを指定します。 6. 完了です。 @@ -50,24 +48,25 @@ Redmine に自動で連番を付加するカスタムフィールドを提供す ## Supported versions -* Redmine 4.0 (Ruby 2.2, 2.3, 2.4, 2.5, 2.6) +* Redmine 4.1 (Ruby 2.6) ## Format specifications -|採番対象の日付 |年表記フォーマット |年度(4/1 - 3/31)|連番フォーマット |結果 | -|----------------|-------------------|----------------|----------------|------------------------| -|Issue#created_on|`yy` |No |000 |2015-03-01 => '15001' | -|Issue#created_on|`yyyy` |No |0000 |2015-03-01 => '20150001'| -|Issue#created_on|`YY` |Yes |000 |2015-03-01 => '14001' | -|Issue#created_on|`YYYY` |Yes |0000 |2015-03-01 => '20140001'| +|採番対象の日付 |年表記書式 |年度(4/1 - 3/31) |例: 正規表現 |例: 結果(2015-03-31) | +|---------------------------|-----------|-----------------------|-------------------------|-----------------------| +|Issue#created_on |`yyyy` |No |`{yyyy}-{0000}` |`2015-0001` | +|^ |`yy` |No |`{yy}-{0000}` |`15-0001` | +|^ |`YYYY` |Yes |`{YYYY}-{0000}` |`2014-0001` | +|^ |`YY` |Yes |`{YY}-{0000}` |`14-0001` | +|^ |`ISO` |No |`{ISO}-{0000}` |`20150331-0001` | * OK * `{000000}` #=> `000001` * `ABC-{yy}-{00}` #=> `ABC-15-01` * NG - * 末尾が連番フォーマットでない場合 + * 末尾が連番書式でない場合 * e.g. `ABC-{000}-{yy}` - * 年表記フォーマット、連番フォーマットでない場合 + * 年表記書式、連番書式でない場合 * e.g. `{abc}-{yy}-{000}` ## Install diff --git a/app/patches/issue_patch.rb b/app/patches/issue_patch.rb index d5bfb35..5d7573d 100644 --- a/app/patches/issue_patch.rb +++ b/app/patches/issue_patch.rb @@ -10,7 +10,7 @@ module IssuePatch def assign_serial_number! serial_number_fields.each do |cf| - next if assigned_serial_number?(cf) + next if assigned_serial_number?(cf) && !copy? target_custom_value = serial_number_custom_value(cf) new_serial_number = cf.format.generate_value(cf, self) diff --git a/app/views/custom_fields/formats/_serial_number.html.erb b/app/views/custom_fields/formats/_serial_number.html.erb index 626b98e..0f26ebb 100644 --- a/app/views/custom_fields/formats/_serial_number.html.erb +++ b/app/views/custom_fields/formats/_serial_number.html.erb @@ -5,6 +5,7 @@ {yy}-{0000} #=> 15-0001 {YYYY}-{0000} #=> 2014-0001 {YY}-{0000} #=> 14-0001 + {ISO}-{0000} #=> 20150331-0001

<%= f.hidden_field :is_required, :value => '0' %> diff --git a/app/views/issues/_remove_serial_number_field.html.erb b/app/views/issues/_remove_serial_number_field.html.erb index 25ba95e..83fba0b 100644 --- a/app/views/issues/_remove_serial_number_field.html.erb +++ b/app/views/issues/_remove_serial_number_field.html.erb @@ -1,7 +1,8 @@ diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 9d6f8d4..f687b40 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -4,5 +4,5 @@ ja: activerecord: errors: messages: - end_must_numeric_format_in_serial_number: "の末尾は連番フォーマットでなければなりません。" - invalid_format_in_serial_number: "に無効なフォーマットが含まれています。" + end_must_numeric_format_in_serial_number: "の末尾は連番書式でなければなりません。" + invalid_format_in_serial_number: "に無効な書式が含まれています。" diff --git a/init.rb b/init.rb index 0335005..d98abec 100644 --- a/init.rb +++ b/init.rb @@ -2,8 +2,8 @@ name 'Redmine Serial Number Field' author 'Matsukei Co.,Ltd' description 'Add a format to be serial number in the specified format as a issue custom field.' - version '2.0.0' - requires_redmine version_or_higher: '4.0' + version '3.0.0' + requires_redmine version_or_higher: '4.1' url 'https://github.com/matsukei/redmine_serial_number_field' author_url 'http://www.matsukei.co.jp/' end diff --git a/lib/format.rb b/lib/format.rb index 1524be0..105186b 100644 --- a/lib/format.rb +++ b/lib/format.rb @@ -7,17 +7,13 @@ class Format < Redmine::FieldFormat::Base self.customized_class_names = %w(Issue) self.form_partial = 'custom_fields/formats/serial_number' - MATCHERS = { - :TOW_DIGIT_NUMBER => /\d{2}/, - :FOUR_DIGIT_NUMBER => /\d{4}/, - :FORMAT_WRAPPER => /\{(.+?)\}/ - } - + FORMAT_WRAPPER = /\{(.+?)\}/ DATE_FORMATS = { - :'yyyy' => { :strftime => '%Y', :financial_year => false, :regexp => MATCHERS[:FOUR_DIGIT_NUMBER] }, - :'yy' => { :strftime => '%y', :financial_year => false, :regexp => MATCHERS[:TOW_DIGIT_NUMBER] }, - :'YYYY' => { :strftime => '%Y', :financial_year => true, :regexp => MATCHERS[:FOUR_DIGIT_NUMBER] }, - :'YY' => { :strftime => '%y', :financial_year => true, :regexp => MATCHERS[:TOW_DIGIT_NUMBER] } + :'yyyy' => { :strftime => '%Y', :financial_year => false }, + :'yy' => { :strftime => '%y', :financial_year => false }, + :'YYYY' => { :strftime => '%Y', :financial_year => true }, + :'YY' => { :strftime => '%y', :financial_year => true }, + :'ISO' => { :strftime => '%Y%m%d', :financial_year => false } } def validate_custom_field(custom_field) @@ -60,7 +56,7 @@ def max_custom_value(custom_field, datetime) def replace_format_value(custom_field) if block_given? - custom_field.regexp.gsub(MATCHERS[:FORMAT_WRAPPER]) do |format_value_with_brace| + custom_field.regexp.gsub(FORMAT_WRAPPER) do |format_value_with_brace| # format_value_with_brace #=> e.g. '{yy}', '{0000}' # $1.clone #=> e.g. 'yy', '0000' yield($1.clone) diff --git a/test/database.travis.yml b/test/database.travis.yml deleted file mode 100644 index 350454e..0000000 --- a/test/database.travis.yml +++ /dev/null @@ -1,4 +0,0 @@ -test: - adapter: sqlite3 - database: db/test.sqlite3 - timeout: 500 diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 78510e3..4efd1dd 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -37,8 +37,8 @@ def test_get_new end end - def test_post_create_and_show_and_get_edit_update_with_current_created - # test_post_create + def test_post_create_and_show_and_get_edit_update_with_current_created_and_post_copy + # create assert_difference 'Issue.count' do assert_no_difference 'Journal.count' do post :create, :params => { @@ -100,6 +100,29 @@ def test_post_create_and_show_and_get_edit_update_with_current_created end assert_added_serial_number(issue.id, 'MCC-0001', @default_custom_field) assert_added_serial_number(issue.id, 'MCC-0001', @for_all_custom_field) + + # copy + assert_difference 'Issue.count' do + post :create, :params => { + :project_id => 1, + :issue => { + :tracker_id => 1, + :status_id => 2, + :subject => 'This is the test_copy issue', + :custom_field_values => { + @default_custom_field.id => 'MCC-0001' + } + }, + :copy_from => issue.id, + :link_copy => 1 + } + end + copied_issue = Issue.find_by_subject('This is the test_copy issue') + assert_redirected_to :controller => 'issues', :action => 'show', :id => copied_issue.id + + assert_not_equal(issue.id, copied_issue.id) + assert_added_serial_number(copied_issue.id, 'MCC-0002', @default_custom_field) + assert_added_serial_number(copied_issue.id, 'MCC-0002', @for_all_custom_field) end def test_show_with_already_created diff --git a/test/test_helper.rb b/test/test_helper.rb index 8c96dd7..059404f 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -47,6 +47,7 @@ def valid_regexp_values [ '{yyyy}-{0000}', '{yy}-{0000}', '{YYYY}-{0000}', '{YY}-{0000}', + '{ISO}-{000}', '{0000}', '#{yyyy}-{00000}', 'OCG-{yy}-{00000}', '日本語{YYYY}-{00000}', ' {YY}-{00000}', '!{00000}'