Skip to content

Commit

Permalink
Merge pull request #95 from akiko-pusu/develop
Browse files Browse the repository at this point in the history
Release v0.1.0 / for Redmine4.x
  • Loading branch information
akiko-pusu authored Jul 8, 2019
2 parents 8e26560 + 3534aef commit 6ce59f1
Show file tree
Hide file tree
Showing 30 changed files with 270 additions and 215 deletions.
69 changes: 11 additions & 58 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ version: 2

general:
artifacts:
- coverage/${CIRCLE_PROJECT_REPONAME}_test/index.html
- coverage/${CIRCLE_PROJECT_REPONAME}_spec/index.html

jobs:
build:
docker:
# specify the version you desire here
- image: circleci/ruby:2.4.1-node-browsers
# specify the version you desire here (ruby 2.6.x)
- image: circleci/ruby:2.6-browsers-legacy
steps:
- checkout
test:
docker:
# specify the version you desire here
- image: circleci/ruby:2.4.1-node-browsers
- image: circleci/ruby:2.6-browsers-legacy
environment:
RAILS_ENV: test
DB_HOST: 127.0.0.1
Expand All @@ -30,71 +30,34 @@ jobs:
MYSQL_USER: root
MYSQL_ALLOW_EMPTY_PASSWORD: yes

working_directory: ~/repo
steps:
- checkout
- run:
name: ready for redmine
command: |
REDMINE_BRANCH=3.4-stable sh script/circleci-setup.sh
- run: bundle install --path vendor/bundle --without postgresql rmagick && bundle update
- run: bundle exec rake db:create RAILS_ENV=test
- run: bundle exec rake db:migrate RAILS_ENV=test
- run: bundle exec rake redmine:plugins:migrate RAILS_ENV=test
- run:
command: |
bundle exec rake ${CIRCLE_PROJECT_REPONAME}:spec RAILS_ENV=test
- run:
command: |
bundle exec rake redmine:plugins:migrate NAME=${CIRCLE_PROJECT_REPONAME} \
VERSION=0 RAILS_ENV=test
- run:
command: |
mkdir -p /tmp/coverage
cp -r coverage/${CIRCLE_PROJECT_REPONAME}_test /tmp/coverage/
- store_artifacts:
path: /tmp/coverage

trunk_test:
docker:
# specify the version you desire here
- image: circleci/ruby:2.4.1-node-browsers
environment:
RAILS_ENV: test
DB_HOST: 127.0.0.1
TZ: /usr/share/zoneinfo/Asia/Tokyo
- image: mysql:5.7
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_bin --innodb-large-prefix=true --innodb-file-format=Barracuda --sql-mode=""
environment:
MYSQL_USER: root
MYSQL_ALLOW_EMPTY_PASSWORD: yes

working_directory: ~/repo
steps:
- checkout
- run:
name: ready for redmine
command: |
REDMINE_BRANCH=master sh script/circleci-setup.sh
- run: perl -pi -e "s/gem \"capybara\".*$/gem \"capybara\"/g" Gemfile
- run: bundle install --path vendor/bundle --without postgresql rmagick && bundle update
- run: bundle exec rails g rspec:install
- run: bundle exec rake db:create RAILS_ENV=test
- run: bundle exec rake db:migrate RAILS_ENV=test
- run: bundle exec rake redmine:plugins:migrate RAILS_ENV=test
- run:
command: |
bundle exec rake ${CIRCLE_PROJECT_REPONAME}:spec RAILS_ENV=test
bundle exec rspec -I plugins/${CIRCLE_PROJECT_REPONAME}/spec --format documentation plugins/${CIRCLE_PROJECT_REPONAME}/spec/
- run:
command: |
bundle exec rake redmine:plugins:migrate NAME=${CIRCLE_PROJECT_REPONAME} \
VERSION=0 RAILS_ENV=test
- run:
command: |
mkdir -p /tmp/coverage
cp -r coverage/${CIRCLE_PROJECT_REPONAME}_test /tmp/coverage/
cp -r coverage/${CIRCLE_PROJECT_REPONAME}_spec /tmp/coverage/
- store_artifacts:
path: /tmp/coverage


workflows:
version: 2
build_and_test:
Expand All @@ -105,15 +68,5 @@ workflows:
- build
filters:
branches:
only:
- develop
- master
- /gh-.*/
- trunk_test:
requires:
- build
filters:
branches:
only:
- support-rails5
- /trunk-.*/
ignore:
- /support-Redmine3.*/
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
inherit_from: .rubocop_todo.yml
AllCops:
# TODO: Change TargetRubyVersion to 2.0 or higher, when Redmine cloded to support ruby 1.9x.
TargetRubyVersion: 2.3
17 changes: 11 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ruby:2.4
FROM ruby:2.5
LABEL maintainer="AKIKO TAKANO / (Twitter: @akiko_pusu)" \
description="Image to run Redmine simply with sqlite to try/review plugin."

Expand All @@ -14,10 +14,9 @@ RUN apt-get install -qq -y \
sqlite3 default-libmysqlclient-dev
RUN apt-get install -qq -y build-essential libc6-dev

RUN cd /tmp && svn co http://svn.redmine.org/redmine/branches/3.4-stable/ redmine
RUN cd /tmp && svn co http://svn.redmine.org/redmine/trunk redmine
WORKDIR /tmp/redmine


# add database.yml (for development, development with mysql, test)
RUN echo $'test:\n\
adapter: sqlite3\n\
Expand All @@ -26,9 +25,15 @@ RUN echo $'test:\n\
development:\n\
adapter: sqlite3\n\
database: /tmp/data/redmine_development.sqlite3\n\
encoding: utf8mb4\n'\
encoding: utf8mb4\n\
development_mysql:\n\
adapter: mysql2\n\
host: mysql\n\
password: pasword\n\
database: redemine_development\n\
username: root\n'\
>> config/database.yml

RUN gem uninstall bundler
RUN bundle install --without postgresql rmagick mysql
RUN gem update bundler
RUN bundle install --without postgresql rmagick
RUN bundle exec rake db:migrate
6 changes: 4 additions & 2 deletions Gemfile.local
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
source 'https://rubygems.org'

group :test do
gem 'database_cleaner'
gem 'rspec-rails'
gem 'factory_bot_rails'
gem 'launchy'
gem 'poltergeist', require: false
gem 'database_cleaner'
gem 'rspec-rails'
# Test format nyan cat
gem 'nyan-cat-formatter', require: false
end
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

Plugin to show the number of assigned issues with badge on top menu.

For Redmine 3.x, please use version 0.7.0 or support-Redmine3 branch.

![screen shot](https://raw.githubusercontent.com/wiki/akiko-pusu/redmine_issue_badge/img/screen-in-case-no-assigned-issues.png)

### Plugin installation
Expand All @@ -17,7 +19,7 @@ Plugin to show the number of assigned issues with badge on top menu.

e.g. rake redmine:plugins:migrate RAILS_ENV=production

1. (Re)Start Redmine.
3. (Re)Start Redmine.


### Uninstall
Expand Down Expand Up @@ -63,6 +65,17 @@ Then, you can configure and activate this plugin.

## Changelog

### 0.1.0

* Support Redmine 4.x.
* Now master branch unsupports Redmine 3.x.
* Please use ver **0.7.x** or ``support-Redmine3`` branch
in case using Redmine3.x.

NOTE: Mainly, maintenance and refactoring only. There is no additional feature, translation in this release.
Thank you so much for providing workaround against Redmine4.x, @kenji21! (#91, #92)


### 0.0.7

* Feature #82. Enabled to switch list issue order. (Oldest 5 or Latest 5)
Expand Down Expand Up @@ -134,6 +147,26 @@ From this version, need Redmine 3.3.1 or higher.

* https://github.com/akiko-pusu/redmine_issue_badge

### Run spec

Please see .circleci/config.yml for more details.
You can run only for the spec related this plugin via rake task.

```
$ cd REDMINE_ROOT_DIR
$ cp plugins/redmine_issue_badge/Gemfile.local plugins/redmine_issue_badge/Gemfile
$ bundle install --with test
$ export RAILS_ENV=test
$ bundle exec rake redmine_issue_badge:spec
```

Also you can run via rspec command like this:

```
$ bundle exec rspec -I plugins/redmine_issue_badge/spec \
--format documentation plugins/redmine_issue_badge/spec/
```


### License

Expand Down
6 changes: 4 additions & 2 deletions app/controllers/issue_badge_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class IssueBadgeController < ApplicationController
layout 'base'
helper :issues
Expand All @@ -11,8 +13,8 @@ def index
end

def issues_count
render(text: { status: false }.to_json) && return if User.current.anonymous?
render text: { status: true, all_issues_count: all_issues.count }.to_json
render(plain: { status: false }.to_json) && return if User.current.anonymous?
render plain: { status: true, all_issues_count: all_issues.count }.to_json
end

def load_badge_contents
Expand Down
44 changes: 28 additions & 16 deletions app/models/issue_badge_user_setting.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
class IssueBadgeUserSetting < ActiveRecord::Base
belongs_to :user
validates_presence_of :user
enum badge_order: { oldest: 0, newest: 1 }
# frozen_string_literal: true

def self.find_or_create_by_user_id(user)
issue_badge = IssueBadgeUserSetting.where(user_id: user.id).first
unless issue_badge
issue_badge = IssueBadgeUserSetting.new
issue_badge.user = user
end
issue_badge
end
class IssueBadgeUserSetting < ActiveRecord::Base # rubocop:disable Rails/ApplicationRecord
include Redmine::SafeAttributes
belongs_to :user
validates :user, presence: true
safe_attributes 'enabled', 'show_assigned_to_group'

def self.destroy_by_user_id(user_id)
issue_badge = IssueBadgeUserSetting.where(user_id: user_id).first
issue_badge.destroy if issue_badge
end
enum badge_order: { oldest: 0, newest: 1 }
scope :enabled, -> { where(enabled: true) }
scope :show_assigned_to_group, -> { where(show_assigned_to_group: true) }

def enabled?
# noinspection RubyResolve
Expand All @@ -25,4 +18,23 @@ def enabled?
def show_assigned_to_group?
show_assigned_to_group
end

#
# Class method
#
class << self
def find_or_create_by_user_id(user)
issue_badge = IssueBadgeUserSetting.find_by(user_id: user.id)
unless issue_badge
issue_badge = IssueBadgeUserSetting.new
issue_badge.user = user
end
issue_badge
end

def destroy_by_user_id(user_id)
issue_badge = IssueBadgeUserSetting.find_by(user_id: user_id)
issue_badge&.destroy
end
end
end
2 changes: 1 addition & 1 deletion db/migrate/001_create_issue_badge_user_settings.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateIssueBadgeUserSettings < ActiveRecord::Migration
class CreateIssueBadgeUserSettings < ActiveRecord::Migration[4.2]
def change
create_table :issue_badge_user_settings do |t|
t.integer :user_id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class AddShowAssignedToGroupToIssueBadgeUserSettings < ActiveRecord::Migration
class AddShowAssignedToGroupToIssueBadgeUserSettings < ActiveRecord::Migration[4.2]
def self.up
add_column :issue_badge_user_settings, :show_assigned_to_group, :boolean
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class AddBadgeOrderToIssueBadgeUserSettings < ActiveRecord::Migration
class AddBadgeOrderToIssueBadgeUserSettings < ActiveRecord::Migration[4.2]
def self.up
add_column :issue_badge_user_settings, :badge_order, :integer, default: 0
end
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ services:
image: redmine_sqlite3
container_name: redmine_sqlite3
command: >
bash -c "bundle &&
bash -c "svn update &&
bundle &&
bundle exec rake db:migrate &&
bundle exec rake redmine:plugins:migrate &&
bundle exec rake generate_secret_token &&
Expand Down
Loading

0 comments on commit 6ce59f1

Please sign in to comment.