diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..1c625a7 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,47 @@ +# [Choice] Ruby version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.0, 2, 2.7, 2.6, 3-bullseye, 3.0-bullseye, 2-bullseye, 2.7-bullseye, 2.6-bullseye, 3-buster, 3.0-buster, 2-buster, 2.7-buster, 2.6-buster +ARG VARIANT=2-bullseye +FROM mcr.microsoft.com/vscode/devcontainers/ruby:0-${VARIANT} + +# Install Rails +RUN gem install rails webdrivers + +# Default value to allow debug server to serve content over GitHub Codespace's port forwarding service +# The value is a comma-separated list of allowed domains +ENV RAILS_DEVELOPMENT_HOSTS=".githubpreview.dev" + +# [Choice] Node.js version: lts/*, 16, 14, 12, 10 +ARG NODE_VERSION="lts/*" +RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1" + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment this line to install additional gems. +# RUN gem install + +# [Optional] Uncomment this line to install global node packages. +# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 + +RUN apt-get update +RUN apt-get install -y imagemagick + +WORKDIR /usr/local +ARG REDMINE_VERSION=master +RUN git clone https://github.com/redmine/redmine.git -b ${REDMINE_VERSION} +WORKDIR /usr/local/redmine +COPY .devcontainer/database.yml /usr/local/redmine/config/database.yml + +RUN rm -rf .git +RUN echo "gem 'ruby-debug-ide'" >> Gemfile +RUN echo "gem 'debase'" >> Gemfile +RUN echo "gem 'rufo'" >> Gemfile +ENV DB=sqlite3 +RUN bundle install +RUN bundle exec rake db:migrate +RUN bundle exec rake db:migrate RAILS_ENV=test +RUN bundle exec rake test:scm:setup:all +COPY .devcontainer/launch.json /usr/local/redmine/.vscode/launch.json +RUN chown -R vscode . + +COPY .devcontainer/post-create.sh /post-create.sh \ No newline at end of file diff --git a/.devcontainer/create-db-user.sql b/.devcontainer/create-db-user.sql new file mode 100644 index 0000000..291dfc4 --- /dev/null +++ b/.devcontainer/create-db-user.sql @@ -0,0 +1,2 @@ +CREATE USER vscode CREATEDB; +CREATE DATABASE vscode WITH OWNER vscode; diff --git a/.devcontainer/database.yml b/.devcontainer/database.yml new file mode 100644 index 0000000..5107702 --- /dev/null +++ b/.devcontainer/database.yml @@ -0,0 +1,57 @@ +# SQLite version 3.x +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +# +sqlite3: &sqlite3 + adapter: sqlite3 + pool: 5 + timeout: 5000 + database: db/redmine.sqlite3 + +sqlite3_test: &sqlite3_test + <<: *<%= 'sqlite3' %> + database: db/redmine.sqlite3_test + +mysql: &mysql + adapter: mysql2 + encoding: utf8 + database: <%= ENV['DB_NAME'] || 'redmine' %> + username: <%= ENV['DB_USERNAME'] || 'root' %> + password: <%= ENV['DB_PASSWORD'] || 'root' %> + host: <%= ENV['DB_HOST'] || 'mysql' %> + port: <%= ENV['DB_PORT'] || 3306 %> + +mysql_test: &mysql_test + <<: *<%= 'mysql' %> + database: redmine_test + +postgres: &postgres + adapter: postgresql + encoding: utf8 + database: <%= ENV['DB_NAME'] || 'redmine' %> + username: <%= ENV['DB_USERNAME'] || 'postgres' %> + password: <%= ENV['DB_PASSWORD'] || 'postgres' %> + host: <%= ENV['DB_HOST'] || 'postgres' %> + port: <%= ENV['DB_PORT'] || 5432 %> + +postgres_test: &postgres_test + <<: *<%= 'postgres' %> + database: redmine_test + + +development: + <<: *<%= ENV['DB'] || 'sqlite3' %> + + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *<%= "#{ENV['DB']}_test" || 'sqlite3_test' %> + + +production: + <<: *<%= ENV['DB'] || 'sqlite3' %> + diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..fa994ff --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,64 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.202.5/containers/ruby-rails-postgres +// Update the VARIANT arg in docker-compose.yml to pick a Ruby version +{ + "name": "Ruby on Rails & Postgres", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + + "workspaceFolder": "/usr/local/redmine", + + // Set *default* container specific settings.json values on container create. + "settings": { + "sqltools.connections": [ + { + "name": "Rails Development Database", + "driver": "PostgreSQL", + "previewLimit": 50, + "server": "localhost", + "port": 5432, + + // update this to match config/database.yml + "database": "app_development", + "username": "vscode" + }, + { + "name": "Rails Test Database", + "driver": "PostgreSQL", + "previewLimit": 50, + "server": "localhost", + "port": 5432, + + // update this to match config/database.yml + "database": "app_test", + "username": "vscode" + } + ] + }, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "rebornix.Ruby", + "mtxr.sqltools", + "mtxr.sqltools-driver-pg", + "craigmaslowski.erb", + "hridoy.rails-snippets", + "misogi.ruby-rubocop", + "jnbt.vscode-rufo", + "donjayamanne.git-extension-pack" + ], + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [3000, 5432], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "sh -x /post-create.sh", + + // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode", + "features": { + // "git": "latest" + } + + +} \ No newline at end of file diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..5f06b98 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,58 @@ +version: '3' + +services: + app: + build: + context: .. + dockerfile: .devcontainer/Dockerfile + args: + # Update 'VARIANT' to pick a version of Ruby: 3, 3.0, 2, 2.7, 2.6 + # Append -bullseye or -buster to pin to an OS version. + # Use -bullseye variants on local arm64/Apple Silicon. + VARIANT: "3.0" + # Optional Node.js version to install + NODE_VERSION: "lts/*" + REDMINE_VERSION: "5.0-stable" + + volumes: + - ..:/usr/local/redmine/plugins/redmine_code_review:cached + + # Overrides default command so things don't shut down after the process ends. + command: sleep infinity + + # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. + # network_mode: service:postgres + # Uncomment the next line to use a non-root user for all processes. + # user: vscode + + # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + + postgres: + image: postgres:latest + restart: unless-stopped + volumes: + - postgres-data:/var/lib/postgresql/data + - ./create-db-user.sql:/docker-entrypoint-initdb.d/create-db-user.sql + environment: + POSTGRES_USER: postgres + POSTGRES_DB: redmine + POSTGRES_PASSWORD: postgres + # Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + + mysql: + image: mysql:latest + restart: unless-stopped + volumes: + - mysql-data:/var/lib/mysql + # network_mode: service:postgres + command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci + environment: + MYSQL_ROOT_PASSWORD: root + MYSQL_USER: redmine + MYSQL_DB: redmine + MYSQL_PASSWORD: remine +volumes: + postgres-data: null + mysql-data: null diff --git a/.devcontainer/launch.json b/.devcontainer/launch.json new file mode 100644 index 0000000..793c4e9 --- /dev/null +++ b/.devcontainer/launch.json @@ -0,0 +1,84 @@ +{ + "version": "0.2.0", + "configurations": [ + + + { + "name": "Rails server", + "type": "Ruby", + "request": "launch", + "program": "${workspaceRoot}/bin/rails", + "useBundler": true, + "args": [ + "server" + ] + }, + { + "name": "Rails server(postgres)", + "type": "Ruby", + "request": "launch", + "program": "${workspaceRoot}/bin/rails", + "useBundler": true, + "args": [ + "server" + ], + "env":{ + "DB": "postgres" + } + }, + { + "name": "Rails server(mysql)", + "type": "Ruby", + "request": "launch", + "program": "${workspaceRoot}/bin/rails", + "useBundler": true, + "args": [ + "server" + ], + "env":{ + "DB": "mysql" + } + }, + { + "name": "Plugin Test", + "type": "Ruby", + "request": "launch", + "program": "${workspaceRoot}/bin/rake", + "useBundler": true, + "args": [ + "redmine:plugins:test" + ], + "env":{ + "RAILS_ENV": "test" + } + }, + { + "name": "Plugin Test(postgres)", + "type": "Ruby", + "request": "launch", + "program": "${workspaceRoot}/bin/rake", + "useBundler": true, + "args": [ + "redmine:plugins:test" + ], + "env":{ + "RAILS_ENV": "test", + "DB": "postgres" + } + }, + { + "name": "Plugin Test(mysql)", + "type": "Ruby", + "request": "launch", + "program": "${workspaceRoot}/bin/rake", + "useBundler": true, + "args": [ + "redmine:plugins:test" + ], + "env":{ + "RAILS_ENV": "test", + "DB": "mysql" + } + } + ] +} \ No newline at end of file diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh new file mode 100644 index 0000000..579728d --- /dev/null +++ b/.devcontainer/post-create.sh @@ -0,0 +1,28 @@ +#!/bin/sh +cd /usr/local/redmine + +cp plugins/redmine_code_review/Gemfile_for_test plugins/redmine_code_review/Gemfile +bundle install + +initdb() { + bundle exec rake db:create + bundle exec rake db:migrate + bundle exec rake redmine:plugins:migrate + + bundle exec rake db:drop RAILS_ENV=test + bundle exec rake db:create RAILS_ENV=test + bundle exec rake db:migrate RAILS_ENV=test + bundle exec rake redmine:plugins:migrate RAILS_ENV=test +} + +export DB=sqlite3 + +initdb + +export DB=postgres + +initdb + +export DB=mysql + +initdb \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..0786b00 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,68 @@ +name: build +on: [push, pull_request] +env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + db: [sqlite3, mysql, postgres] + ruby_version: [2.4, 2.5, 2.6, 2.7, 3.0, 3.1] + redmine_version: [4.1-stable, 4.2-stable, 5.0-stable, master] + exclude: + - ruby_version: 2.4 + redmine_version: master + - ruby_version: 2.4 + redmine_version: 5.0-stable + - ruby_version: 2.7 + redmine_version: 4.1-stable + - ruby_version: 3.0 + redmine_version: 4.1-stable + - ruby_version: 3.0 + redmine_version: 4.2-stable + - ruby_version: 3.1 + redmine_version: 4.1-stable + - ruby_version: 3.1 + redmine_version: 4.2-stable + services: + mysql: + image: mysql:5.7 + options: --health-cmd "mysqladmin ping -h localhost" --health-interval 20s --health-timeout 10s --health-retries 10 + env: + MYSQL_ROOT_PASSWORD: dbpassword + postgres: + image: postgres + env: + POSTGRES_USER: root + POSTGRES_PASSWORD: dbpassword + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + container: + image: ruby:${{ matrix.ruby_version }} + env: + DB: ${{ matrix.db }} + DB_USERNAME: root + DB_PASSWORD: dbpassword + DB_HOST: ${{ matrix.db }} + REDMINE_VER: ${{ matrix.redmine_version }} + steps: + - uses: actions/checkout@v2 + - name: Install + run: bash -x ./build-scripts/install.sh + - name: Build + run: bash -x ./build-scripts/build.sh + - name: Clean + run: bash -x ./build-scripts/cleanup.sh + - uses: codecov/codecov-action@v2 + - name: Slack Notification on Failure + uses: rtCamp/action-slack-notify@v2.0.2 + if: failure() + env: + SLACK_CHANNEL: plugin-code_review + SLACK_TITLE: Test Failure + SLACK_COLOR: danger + diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..0dfe05f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,46 @@ +name: build_archive +on: + push: + branches-ignore: + - '**' + tags: + - '**' +env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} +jobs: + archive: + runs-on: ubuntu-latest + steps: + - name: Set version + id: version + run: | + REPOSITORY=$(echo ${{ github.repository }} | sed -e "s#.*/##") + VERSION=$(echo ${{ github.ref }} | sed -e "s#refs/tags/##g") + echo ::set-output name=version::$VERSION + echo ::set-output name=filename::$REPOSITORY-$VERSION + echo ::set-output name=plugin::$REPOSITORY + - uses: actions/checkout@v2 + - name: Archive + run: | + cd ..; zip -r ${{ steps.version.outputs.filename }}.zip ${{ steps.version.outputs.plugin }}/ -x "*.git*"; mv ${{ steps.version.outputs.filename }}.zip ${{ steps.version.outputs.plugin }}/ + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.version.outputs.version }} + release_name: ${{ steps.version.outputs.version }} + body: '' + draft: false + prerelease: true + - name: Upload Release Asset + id: upload-release-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ${{ steps.version.outputs.filename }}.zip + asset_name: ${{ steps.version.outputs.filename }}.zip + asset_content_type: application/zip \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 29c721d..21eea86 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,24 @@ language: ruby rvm: -- 2.3 - 2.4 - 2.5 +- 2.6 +- 2.7 +- 3.0 env: +- REDMINE_VER=4.1-stable +- REDMINE_VER=4.2-stable - REDMINE_VER=master -- REDMINE_VER=4.0-stable +matrix: + exclude: + - rvm: 2.4 + env: REDMINE_VER=master + - rvm: 2.7 + env: REDMINE_VER=4.1-stable + - rvm: 3.0 + env: REDMINE_VER=4.1-stable + - rvm: 3.0 + env: REDMINE_VER=4.2-stable install: - bash -x ./travis/travis_install.sh script: diff --git a/Gemfile_for_test b/Gemfile_for_test index 2d8d66d..238c4f0 100644 --- a/Gemfile_for_test +++ b/Gemfile_for_test @@ -2,8 +2,8 @@ group :test do gem "simplecov-rcov" + gem "simplecov-lcov" gem 'factory_bot_rails' gem 'shoulda' gem 'rails-controller-testing' - gem 'coveralls', :require => false end \ No newline at end of file diff --git a/README.rdoc b/README.md similarity index 63% rename from README.rdoc rename to README.md index e0867a0..5df6b55 100644 --- a/README.rdoc +++ b/README.md @@ -1,13 +1,14 @@ -{Build Status}[https://travis-ci.org/haru/redmine_code_review] -{Coverage Status}[https://coveralls.io/github/haru/redmine_code_review?branch=master] +[![build](https://github.com/haru/redmine_code_review/actions/workflows/build.yml/badge.svg)](https://github.com/haru/redmine_code_review/actions/workflows/build.yml) +[![Maintainability](https://api.codeclimate.com/v1/badges/adc7bcbf7bfd8e80a97b/maintainability)](https://codeclimate.com/github/haru/redmine_code_review/maintainability) +[![codecov](https://codecov.io/gh/haru/redmine_code_review/branch/develop/graph/badge.svg?token=37CJ55KBUU)](https://codecov.io/gh/haru/redmine_code_review) -= Redmine Code Review Plugin +# Redmine Code Review Plugin This is a plugin for Redmine which lets you annotate source code within the repository browser. http://www.r-labs.org/wiki/r-labs/Code_Review -=== Plugin installation +## Plugin installation 1. Copy the plugin directory into the plugins directory @@ -22,7 +23,7 @@ http://www.r-labs.org/wiki/r-labs/Code_Review 6. Go to "Roles and permissions" and add "Code Review" permissions to the roles you want to see/edit/manage code reviews. -=== Language contributors +## Language contributors * de.yml - Michael Diederich, Sebastian Bernhard * fr.yml - Thomas M, fcrespel diff --git a/app/controllers/code_review_controller.rb b/app/controllers/code_review_controller.rb index d64143b..0e3ec0b 100644 --- a/app/controllers/code_review_controller.rb +++ b/app/controllers/code_review_controller.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009-2015 Haruyuki Iida +# Copyright (C) 2009-2022 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -17,7 +17,7 @@ class CodeReviewController < ApplicationController unloadable - before_action :find_project, :authorize, :find_user, :find_setting, :find_repository + before_action :find_project, :authorize, :find_user, :find_setting, :find_repository, :find_priorities helper :sort include SortHelper @@ -83,6 +83,7 @@ def new @review.attachment_id = params[:attachment_id].to_i unless params[:attachment_id].blank? @issue = @review.issue @review.issue.safe_attributes = params[:issue] unless params[:issue].blank? + @review.repository_id = params[:repository_id] unless params[:repository_id].blank? @review.diff_all = (params[:diff_all] == 'true') @parent_candidate = get_parent_candidate(@review.rev) if @review.rev @@ -375,6 +376,10 @@ def find_setting @setting = CodeReviewProjectSetting.find_or_create(@project) end + def find_priorities + @priorities = IssuePriority.active + end + def get_parent_candidate(revision) changeset = @repository.find_changeset_by_name(revision) changeset.issues.each { |issue| diff --git a/app/models/code_review.rb b/app/models/code_review.rb index bf81b44..0a17216 100644 --- a/app/models/code_review.rb +++ b/app/models/code_review.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009-2017 Haruyuki Iida +# Copyright (C) 2009-2022 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -92,6 +92,7 @@ def repository end def repository_identifier + return repository_id if repository_id return nil unless repository @repository_identifier ||= repository.identifier_param end diff --git a/app/views/code_review/_issues_show_details_bottom.html.erb b/app/views/code_review/_issues_show_details_bottom.html.erb index 62463e9..d248bbe 100644 --- a/app/views/code_review/_issues_show_details_bottom.html.erb +++ b/app/views/code_review/_issues_show_details_bottom.html.erb @@ -19,9 +19,9 @@ review = issue.code_review <% if review.attachment - label = URI.decode("#{review.attachment.filename}#{'@' + review.revision if review.revision}:line #{review.line}") + label = URI.decode_www_form_component("#{review.attachment.filename}#{'@' + review.revision if review.revision}:line #{review.line}") else - label = URI.decode("#{review.repository_identifier + ':' if review.repository_identifier}#{review.path}#{'@' + review.revision if review.revision}:line #{review.line}") + label = URI.decode_www_form_component("#{review.repository_identifier + ':' if review.repository_identifier}#{review.path}#{'@' + review.revision if review.revision}:line #{review.line}") end -%> <%= link_to(label, @@ -39,7 +39,7 @@ review = issue.code_review <% if assignment.path %> <% - label = URI.decode("#{repository_id + ':' if repository_id}#{assignment.path}#{'@' + assignment.revision if assignment.revision}") + label = URI.decode_www_form_component("#{repository_id + ':' if repository_id}#{assignment.path}#{'@' + assignment.revision if assignment.revision}") -%> <%= link_to(label, :controller => 'code_review', :action => 'show', :id => project, :assignment_id => assignment.id, :repository_id => repository_id) %> diff --git a/app/views/code_review/_new_form.html.erb b/app/views/code_review/_new_form.html.erb index df6748b..5f9e1e5 100644 --- a/app/views/code_review/_new_form.html.erb +++ b/app/views/code_review/_new_form.html.erb @@ -66,6 +66,10 @@ <% end %>

+

+ + <%= select :issue, :priority_id, (@priorities.collect {|p| [p.name, p.id]}), :required => true %> +

<% @issue.custom_field_values.each do |value| %> <% next unless value.required? -%>

<%= custom_field_tag_with_label :issue, value %>

diff --git a/app/views/code_review/index.html.erb b/app/views/code_review/index.html.erb index c82a9c0..2e532e2 100644 --- a/app/views/code_review/index.html.erb +++ b/app/views/code_review/index.html.erb @@ -74,7 +74,7 @@ function change_option(flag) { <% - review_path = URI.decode(review.path) + review_path = URI.decode_www_form_component(review.path) codepath = review_path if (review_path.length > 55) codepath = review_path[0, 15] + '...' + review_path[review_path.length - 35, 35] diff --git a/assets/javascripts/code_review.js b/assets/javascripts/code_review.js index a2ea33d..05305bd 100644 --- a/assets/javascripts/code_review.js +++ b/assets/javascripts/code_review.js @@ -81,7 +81,7 @@ function UpdateRevisionView() { if (li.hasClass('folder')) return; var a = li.down('a'); - if (a.size() == 0) return; + if (a.length == 0) return; var path = a.attr('href').replace(urlprefix, '').replace(/\?.*$/, ''); var reviewlist = code_reviews_map[path]; @@ -186,7 +186,7 @@ var showClosedReviewImageTag = null; function setShowReviewButton(line, review_id, is_closed, file_count) { //alert('file_count = ' + file_count); var span = $('#review_span_' + line + '_' + file_count); - if (span.size() == 0) { + if (span.length == 0) { return; } var innerSpan = $('', { @@ -249,7 +249,6 @@ function showReview(url, review_id, x, y) { topZindex++; code_reviews_dialog_map[review_id] = win; $('.ui-dialog').appendTo('#content'); - $('.ui-effects-wrapper').zIndex(0); return win } @@ -285,7 +284,6 @@ function formPopup(x, y) { review_form_dialog = win; topZindex += 10; $('.ui-dialog').appendTo('#content'); - $('.ui-effects-wrapper').zIndex(0); return false; } diff --git a/build-scripts/build.sh b/build-scripts/build.sh new file mode 100644 index 0000000..d86b420 --- /dev/null +++ b/build-scripts/build.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e + +cd `dirname $0` +. env.sh +cd .. + +if [ "$NAME_OF_PLUGIN" == "" ] +then + export NAME_OF_PLUGIN=`basename $PATH_TO_PLUGIN` +fi + +cd $PATH_TO_REDMINE + +# create scms for test +bundle exec rake test:scm:setup:all + +# run tests +# bundle exec rake TEST=test/unit/role_test.rb +bundle exec rake redmine:plugins:test NAME=$NAME_OF_PLUGIN + diff --git a/build-scripts/cleanup.sh b/build-scripts/cleanup.sh new file mode 100644 index 0000000..d3426ae --- /dev/null +++ b/build-scripts/cleanup.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +cd `dirname $0` +. env.sh +cd .. + +rm -rf $TESTSPACE \ No newline at end of file diff --git a/build-scripts/database.yml b/build-scripts/database.yml new file mode 100644 index 0000000..9017a3f --- /dev/null +++ b/build-scripts/database.yml @@ -0,0 +1,43 @@ +# SQLite version 3.x +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +# +sqlite3: &sqlite3 + adapter: sqlite3 + pool: 5 + timeout: 5000 + database: db/redmine.sqlite3 + +mysql: &mysql + adapter: mysql2 + encoding: utf8 + database: <%= ENV['DB_NAME'] || 'redmine' %> + username: <%= ENV['DB_USERNAME'] %> + password: <%= ENV['DB_PASSWORD'] %> + host: <%= ENV['DB_HOST'] %> + port: <%= ENV['DB_PORT'] || 3306 %> + +postgres: &postgres + adapter: postgresql + encoding: utf8 + database: <%= ENV['DB_NAME'] || 'redmine' %> + username: <%= ENV['DB_USERNAME'] %> + password: <%= ENV['DB_PASSWORD'] %> + host: <%= ENV['DB_HOST'] %> + port: <%= ENV['DB_PORT'] || 5432 %> + +development: + <<: *<%= ENV['DB'] || 'sqlite3' %> + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *<%= ENV['DB'] || 'sqlite3' %> + +production: + <<: *<%= ENV['DB'] || 'sqlite3' %> + + diff --git a/build-scripts/env.sh b/build-scripts/env.sh new file mode 100644 index 0000000..3ba4f48 --- /dev/null +++ b/build-scripts/env.sh @@ -0,0 +1,5 @@ +export TRAVISDIR=`pwd` +export PATH_TO_PLUGIN=`dirname ${TRAVISDIR}` +export TESTSPACE=$PATH_TO_PLUGIN/testspace +export PATH_TO_REDMINE=$TESTSPACE/redmine +export RAILS_ENV=test \ No newline at end of file diff --git a/build-scripts/install.sh b/build-scripts/install.sh new file mode 100644 index 0000000..71afc09 --- /dev/null +++ b/build-scripts/install.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +set -e + +cd `dirname $0` +. env.sh +SCRIPTDIR=$(pwd) +cd .. + +if [[ ! "$TESTSPACE" = /* ]] || + [[ ! "$PATH_TO_REDMINE" = /* ]] || + [[ ! "$PATH_TO_PLUGIN" = /* ]]; +then + echo "You should set"\ + " TESTSPACE, PATH_TO_REDMINE,"\ + " PATH_TO_PLUGIN"\ + " environment variables" + echo "You set:"\ + "$TESTSPACE"\ + "$PATH_TO_REDMINE"\ + "$PATH_TO_PLUGIN" + exit 1; +fi + +if [ "$REDMINE_VER" = "" ] +then + export REDMINE_VER=master +fi + +if [ "$NAME_OF_PLUGIN" == "" ] +then + export NAME_OF_PLUGIN=`basename $PATH_TO_PLUGIN` +fi + +mkdir -p $TESTSPACE + +export REDMINE_GIT_REPO=https://github.com/redmine/redmine.git +export REDMINE_GIT_TAG=$REDMINE_VER +export BUNDLE_GEMFILE=$PATH_TO_REDMINE/Gemfile + +if [ -f Gemfile_for_test ] +then + cp Gemfile_for_test Gemfile +fi + +# checkout redmine +git clone $REDMINE_GIT_REPO $PATH_TO_REDMINE +if [ -d test/fixtures ] +then + cp test/fixtures/* ${PATH_TO_REDMINE}/test/fixtures/ +fi + +cd $PATH_TO_REDMINE +if [ ! "$REDMINE_GIT_TAG" = "master" ]; +then + git checkout -b $REDMINE_GIT_TAG origin/$REDMINE_GIT_TAG +fi + +# create a link to the backlogs plugin +ln -sf $PATH_TO_PLUGIN plugins/$NAME_OF_PLUGIN + +cp "$SCRIPTDIR/database.yml" config/database.yml + + + +# install gems +bundle install + +# run redmine database migrations +bundle exec rake db:create +bundle exec rake db:migrate + +# run plugin database migrations +bundle exec rake redmine:plugins:migrate + + diff --git a/config/locales/pt-br.yml b/config/locales/pt-BR.yml similarity index 100% rename from config/locales/pt-br.yml rename to config/locales/pt-BR.yml diff --git a/db/migrate/20220312104356_add_repository_id_to_code_reviews.rb b/db/migrate/20220312104356_add_repository_id_to_code_reviews.rb new file mode 100644 index 0000000..11cca43 --- /dev/null +++ b/db/migrate/20220312104356_add_repository_id_to_code_reviews.rb @@ -0,0 +1,5 @@ +class AddRepositoryIdToCodeReviews < ActiveRecord::Migration[5.2] + def change + add_column :code_reviews, :repository_id, :string + end +end diff --git a/init.rb b/init.rb index d0f8bf4..00d23e2 100644 --- a/init.rb +++ b/init.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009-2018 Haruyuki Iida +# Copyright (C) 2009-2022 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -19,7 +19,9 @@ require 'config/initializers/session_store.rb' rescue LoadError end -require 'gravatar' + +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/lib" + require 'code_review_application_hooks' require 'code_review_change_patch' require 'code_review_changeset_patch' @@ -28,31 +30,13 @@ require 'code_review_projects_helper_patch' require 'code_review_attachment_patch' -Rails.configuration.to_prepare do - unless Change.included_modules.include? CodeReviewChangePatch - Change.send(:include, CodeReviewChangePatch) - end - - unless Changeset.included_modules.include? CodeReviewChangesetPatch - Changeset.send(:include, CodeReviewChangesetPatch) - end - - unless Issue.included_modules.include? CodeReviewIssuePatch - Issue.send(:include, CodeReviewIssuePatch) - end - - unless Attachment.included_modules.include? CodeReviewAttachmentPatch - Attachment.send(:include, CodeReviewAttachmentPatch) - end -end - Redmine::Plugin.register :redmine_code_review do name 'Redmine Code Review plugin' author 'Haruyuki Iida' author_url 'http://twitter.com/haru_iida' url "http://www.redmine.org/plugins/redmine_code_review" if respond_to?(:url) description 'This is a Code Review plugin for Redmine' - version '1.0.0' + version '1.1.0' requires_redmine :version_or_higher => '4.0.0' project_module :code_review do diff --git a/lib/code_review_attachment_patch.rb b/lib/code_review_attachment_patch.rb index 41c2047..9f2c584 100644 --- a/lib/code_review_attachment_patch.rb +++ b/lib/code_review_attachment_patch.rb @@ -31,3 +31,5 @@ def self.included(base) # :nodoc: module AttachmentInstanceMethodsCodeReview end + +Attachment.send(:include, CodeReviewAttachmentPatch) \ No newline at end of file diff --git a/lib/code_review_change_patch.rb b/lib/code_review_change_patch.rb index 0e2ad96..048eb1c 100644 --- a/lib/code_review_change_patch.rb +++ b/lib/code_review_change_patch.rb @@ -92,3 +92,5 @@ def review_auto_assign CodeReviewAssignment.create_with_changeset(changeset) end end + +Change.send(:include, CodeReviewChangePatch) \ No newline at end of file diff --git a/lib/code_review_changeset_patch.rb b/lib/code_review_changeset_patch.rb index 7300ece..f3f23b5 100644 --- a/lib/code_review_changeset_patch.rb +++ b/lib/code_review_changeset_patch.rb @@ -181,3 +181,4 @@ def scan_comment_for_issue_ids end Changeset.prepend(ChangesetInstanceMethodsCodeReview) +Changeset.send(:include, CodeReviewChangesetPatch) diff --git a/lib/code_review_issue_patch.rb b/lib/code_review_issue_patch.rb index 3a88259..81fc5c8 100644 --- a/lib/code_review_issue_patch.rb +++ b/lib/code_review_issue_patch.rb @@ -31,3 +31,5 @@ def self.included(base) # :nodoc: module IssueInstanceMethodsCodeReview end + +Issue.send(:include, CodeReviewIssuePatch) \ No newline at end of file diff --git a/lib/code_review_projects_helper_patch.rb b/lib/code_review_projects_helper_patch.rb index 06fa67c..345f82e 100644 --- a/lib/code_review_projects_helper_patch.rb +++ b/lib/code_review_projects_helper_patch.rb @@ -17,7 +17,7 @@ require_dependency 'projects_helper' -module ProjectsHelperMethodsCodeReview +module CodeReviewProjectsHelperPatch def project_settings_tabs tabs = super action = {:name => 'code_review', :controller => 'code_review_settings', :action => :show, :partial => 'code_review_settings/show', :label => :code_review} @@ -28,4 +28,4 @@ def project_settings_tabs end end -ProjectsHelper.prepend(ProjectsHelperMethodsCodeReview) +ProjectsHelper.prepend(CodeReviewProjectsHelperPatch) diff --git a/test/fixtures/code_review_project_settings.yml b/test/fixtures/code_review_project_settings.yml index 4c4bb8f..62a3881 100644 --- a/test/fixtures/code_review_project_settings.yml +++ b/test/fixtures/code_review_project_settings.yml @@ -12,10 +12,12 @@ one: updated_by: 1 + assignment_tracker_id: 3 + two: id: 2 - project_id: 1 + project_id: 2 tracker_id: 1 @@ -25,3 +27,5 @@ two: updated_by: 1 + assignment_tracker_id: 3 + diff --git a/test/functional/code_review_controller_test.rb b/test/functional/code_review_controller_test.rb index 8b4bd94..3b88f23 100644 --- a/test/functional/code_review_controller_test.rb +++ b/test/functional/code_review_controller_test.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009-2012 Haruyuki Iida +# Copyright (C) 2009-2022 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -86,6 +86,19 @@ def setup assert_template '_new_form' end + should "new review has repository_id when action_type is diff and repository_id param is specified." do + @request.session[:user_id] = 1 + count = CodeReview.all.length + post :new, :params => {:id => 1, :review => {:line => 1, + :comment => 'aaa', :subject => 'bbb'}, :action_type => 'diff', :repository_id => 1} + assert_response :success + assert_template '_add_success' + assert_equal(count + 1, CodeReview.all.length) + review = assigns(:review) + assert_equal("1", review.repository_identifier) + + end + should "create new review when changeset has related issue" do @request.session[:user_id] = 1 project = Project.find(1) diff --git a/test/functional/repositories_controller_test.rb b/test/functional/repositories_controller_test.rb index 0edb2bd..90790e0 100644 --- a/test/functional/repositories_controller_test.rb +++ b/test/functional/repositories_controller_test.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009-2015 Haruyuki Iida +# Copyright (C) 2009-2020 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -38,10 +38,6 @@ def setup enabled_module.project_id = 1 enabled_module.name = 'repository' enabled_module.save - project = Project.find(1) - repo = Repository.find(10) - project.repository = repo - project.save User.current = nil roles = Role.all diff --git a/test/test_helper.rb b/test/test_helper.rb index bde5bcd..d2483ff 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -17,13 +17,20 @@ require 'simplecov' require 'simplecov-rcov' -require 'coveralls' +require 'simplecov-lcov' require 'factory_bot' require 'shoulda' +SimpleCov::Formatter::LcovFormatter.config do |config| + config.report_with_single_file = true + config.single_report_path = File.expand_path(File.dirname(__FILE__) + '/../coverage/lcov.info') +end + SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ SimpleCov::Formatter::RcovFormatter, - Coveralls::SimpleCov::Formatter + SimpleCov::Formatter::LcovFormatter, + SimpleCov::Formatter::HTMLFormatter + # Coveralls::SimpleCov::Formatter ] SimpleCov.start do @@ -31,6 +38,11 @@ add_filter "/test/" end +FactoryBot::SyntaxRunner.class_eval do + include ActionDispatch::TestProcess + include ActiveSupport::Testing::FileFixtures +end + require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper') include ActionDispatch::TestProcess @@ -40,6 +52,8 @@ end ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', fixtures) +include ActiveSupport::Testing::FileFixtures + # Ensure that we are using the temporary fixture path #ngines::Testing.set_fixture_path @@ -71,11 +85,11 @@ def uploaded_test_file(name, mime) end factory :repository do - project_id 1 - url "file:///#{Rails.root}/tmp/test/subversion_repository" - root_url "file:///#{Rails.root}/tmp/test/subversion_repository" - password "" - login "" + project_id {1} + url {"file:///#{Rails.root}/tmp/test/subversion_repository"} + root_url {"file:///#{Rails.root}/tmp/test/subversion_repository"} + password {""} + login {""} type { scm = 'Subversion' unless Setting.enabled_scm.include?(scm) @@ -83,7 +97,7 @@ def uploaded_test_file(name, mime) end scm } - is_default true + is_default {true} end factory :changeset do @@ -114,27 +128,27 @@ def uploaded_test_file(name, mime) end factory :code_review_assignment do - issue_id 1 + issue_id {1} end factory :issue do - subject 'hoge' + subject {'hoge'} author { User.find(1) } end factory :code_review do - issue_id 1 - updated_by_id 1 - line 10 - action_type 'diff' + issue_id {1} + updated_by_id {1} + line {10} + action_type {'diff'} end factory :code_review_project_setting do - project_id 1 - tracker_id 1 - assignment_tracker_id 1 + project_id {1} + tracker_id {1} + assignment_tracker_id {1} end factory :enabled_module do diff --git a/test/unit/code_review_test.rb b/test/unit/code_review_test.rb index 7a0a492..94ca425 100644 --- a/test/unit/code_review_test.rb +++ b/test/unit/code_review_test.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009 Haruyuki Iida +# Copyright (C) 2009-2022 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -113,6 +113,14 @@ def test_user assert_equal(issue.author_id, 2) end + def test_repository_identifier + review = newreview + review.change.changeset.repository_id = 10 + assert_equal("10", review.repository_identifier) + review.repository_id = "testparam" + assert_equal("testparam", review.repository_id) + end + private def newreview