Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/actions/comment_patch_url.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env ruby

require 'json'

require 'faraday'

REPO = 'redmine-patch-meetup/redmine-dev-mirror'

WORKFLOW_RUN = JSON.parse ENV['WORKFLOW_RUN_JSON']

CONNECTION = Faraday.new('https://api.github.com/') do |conn|
conn.response :raise_error
conn.adapter Faraday.default_adapter
end

def repo_resource(resource)
"repos/#{REPO}/#{resource}"
end

def get_repo_resource(resource)
response = CONNECTION.get repo_resource(resource)
JSON.parse response.body
end

def post_to_repo_resource(resource, body)
response = CONNECTION.post repo_resource(resource),
body.to_json,
"Content-Type" => "application/json",
"Authorization" => "token #{ENV['GITHUB_TOKEN']}"
JSON.parse response.body
end

def patch_artifact_id
response = JSON.parse CONNECTION.get(WORKFLOW_RUN['artifacts_url']).body
patch_artifact = response['artifacts'].find { |artifact| artifact['name'] == 'patch' }
patch_artifact['id']
end

def get_suite_id
suite_url = WORKFLOW_RUN['check_suite_url']
id_start_index = suite_url.rindex('/') + 1
suite_url[id_start_index..-1]
end

def patch_artifact_download_url
"https://github.com/#{REPO}/suites/#{get_suite_id}/artifacts/#{patch_artifact_id}"
end

def pull_request_number
WORKFLOW_RUN['pull_requests'][0]['number']
end

def post_pr_comment(pr_number, comment)
post_to_repo_resource "issues/#{pr_number}/comments", { body: comment }
end

def find_previous_comment_id(pr_number)
comments = get_repo_resource "issues/#{pr_number}/comments"
previous_comment = comments.find { |comment|
comment['body'].include?('Patch can be downloaded [here]') && comment['user']['login'].include?('github-actions')
}
previous_comment['id'] if previous_comment
end

def delete_comment(comment_id)
CONNECTION.delete repo_resource("issues/comments/#{comment_id}"), nil, "Authorization" => "token #{ENV['GITHUB_TOKEN']}"
end

def main
existing_comment_id = find_previous_comment_id(pull_request_number)
delete_comment(existing_comment_id) if existing_comment_id

post_pr_comment pull_request_number, "Patch can be downloaded [here](#{patch_artifact_download_url})"
end

main if __FILE__ == $0
11 changes: 11 additions & 0 deletions .github/actions/test-with-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -x

database=$1

cp ./config/database.$database.yml ./config/database.yml
bundle install --path vendor/bundle --without minimagick
bundle update
bundle exec rake db:create db:migrate
bundle exec rake test
24 changes: 24 additions & 0 deletions .github/workflows/comment-patch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Comment Patch

on:
workflow_run:
workflows:
- Create Patch
types:
- completed
branches-ignore:
- master
- development

jobs:
create-patch:
runs-on: ubuntu-latest
steps:
- name: Install gems
run: sudo gem install faraday
- uses: actions/checkout@v2
- name: Comment Patch URL
run: ./.github/actions/comment_patch_url.rb
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WORKFLOW_RUN_JSON: ${{ toJSON(github.event.workflow_run) }}
32 changes: 32 additions & 0 deletions .github/workflows/create-patch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Create Patch

on:
push:
branches-ignore:
- master
- development

jobs:
create-patch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Create Patch
run: |
git rev-parse --abbrev-ref HEAD > .branch-name
git checkout development
git checkout -b patch
git merge --squash `cat .branch-name`
git config --global user.email "$AUTHOR_EMAIL"
git config --global user.name "$AUTHOR_NAME"
git commit -m "Patch for `cat .branch-name`"
git format-patch development..HEAD --stdout -k > patch.diff
env:
AUTHOR_EMAIL: ${{ github.event.head_commit.author.email }}
AUTHOR_NAME: ${{ github.event.head_commit.author.name }}
- uses: actions/upload-artifact@v2
with:
name: patch
path: patch.diff
93 changes: 93 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Test

on:
push:
branches-ignore:
- master
- development

jobs:
test-with-mysql:
strategy:
fail-fast: false
matrix:
ruby: [2.3, 2.4, 2.5, 2.6]
db_version: [5.7]
runs-on: ubuntu-latest
container:
image: ruby:${{ matrix.ruby }}
services:
db:
image: mysql:${{ matrix.db_version }}
env:
MYSQL_ROOT_PASSWORD: password
ports:
- 3306:3306
steps:
- uses: actions/checkout@v2
- name: Cache gems
uses: actions/cache@v2
with:
path: vendor/bundle
key: ${{ matrix.ruby }}-mysql-${{ hashFiles('**/Gemfile') }}
restore-keys: |
${{ matrix.ruby }}-mysql-
${{ matrix.ruby }}-
- name: Install & run tests
run: ./.github/actions/test-with-db.sh mysql
env:
DB_HOST: db
test-with-postgres:
strategy:
fail-fast: false
matrix:
ruby: [2.3, 2.4, 2.5, 2.6]
db_version: [9.5]
runs-on: ubuntu-latest
container:
image: ruby:${{ matrix.ruby }}
services:
db:
image: postgres:${{ matrix.db_version }}
env:
LANG: C.UTF-8
POSTGRES_INITDB_ARGS: --locale=C.UTF-8
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v2
- name: Cache gems
uses: actions/cache@v2
with:
path: vendor/bundle
key: ${{ matrix.ruby }}-postgres-${{ hashFiles('**/Gemfile') }}
restore-keys: |
${{ matrix.ruby }}-postgres-
${{ matrix.ruby }}-
- name: Install & run tests
run: ./.github/actions/test-with-db.sh postgres
env:
DB_HOST: db
test-with-sqlite:
strategy:
fail-fast: false
matrix:
ruby: [2.3, 2.4, 2.5, 2.6]
runs-on: ubuntu-latest
container:
image: ruby:${{ matrix.ruby }}
steps:
- uses: actions/checkout@v2
- name: Cache gems
uses: actions/cache@v2
with:
path: vendor/bundle
key: ${{ matrix.ruby }}-sqlite-${{ hashFiles('**/Gemfile') }}
restore-keys: |
${{ matrix.ruby }}-sqlite-
${{ matrix.ruby }}-
- name: Install & run tests
run: ./.github/actions/test-with-db.sh sqlite
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@

/node_modules
yarn-error.log

docker-compose.yml
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ end

group :development do
gem "yard"
gem "guard"
gem "guard-minitest"
gem "pry", "<= 0.12.2" if RUBY_VERSION < '2.4'
gem "pry-byebug"
end

group :test do
Expand Down
3 changes: 3 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
guard :minitest, all_on_start: false do
watch(%r{^test/(.*)test(.*)\.rb$})
end
12 changes: 8 additions & 4 deletions app/views/issues/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,27 @@
<div class="<%= @issue.css_classes %> details">
<% if @prev_issue_id || @next_issue_id %>
<div class="next-prev-links contextual">
<%= link_to_if @prev_issue_id,
<span class="previous">
<%= link_to_if @prev_issue_id,
"\xc2\xab #{l(:label_previous)}",
(@prev_issue_id ? issue_path(@prev_issue_id) : nil),
:title => "##{@prev_issue_id}",
:accesskey => accesskey(:previous) %> |
:accesskey => accesskey(:previous) %>
</span>
<% if @issue_position && @issue_count %>
<span class="position">
<%= link_to_if @query_path,
l(:label_item_position, :position => @issue_position, :count => @issue_count),
@query_path %>
</span> |
</span>
<% end %>
<%= link_to_if @next_issue_id,
<span class="next">
<%= link_to_if @next_issue_id,
"#{l(:label_next)} \xc2\xbb",
(@next_issue_id ? issue_path(@next_issue_id) : nil),
:title => "##{@next_issue_id}",
:accesskey => accesskey(:next) %>
</span>
</div>
<% end %>

Expand Down
18 changes: 18 additions & 0 deletions config/database.mysql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
default: &default
adapter: mysql2
host: <%= ENV.fetch('DB_HOST', '127.0.0.1') %>
port: <%= ENV.fetch('DB_PORT', '3306') %>
username: root
password: password

production:
<<: *default
database: redmine_production

development:
<<: *default
database: redmine_development

test:
<<: *default
database: redmine_test
19 changes: 19 additions & 0 deletions config/database.postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
default: &default
adapter: postgresql
encoding: utf8
host: <%= ENV.fetch('DB_HOST', 'localhost') %>
port: <%= ENV.fetch('DB_PORT', '5432') %>
username: postgres
password: postgres

production:
<<: *default
database: redmine_production

development:
<<: *default
database: redmine_development

test:
<<: *default
database: redmine_test
18 changes: 18 additions & 0 deletions config/database.sqlite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Default setup is given for MySQL 5.7.7 or later.
# Examples for PostgreSQL, SQLite3 and SQL Server can be found at the end.
# Line indentation must be 2 spaces (no tabs).

default: &default
adapter: sqlite3

production:
<<: *default
database: db/redmine_production.sqlite3

development:
<<: *default
database: db/redmine_development.sqlite3

test:
<<: *default
database: db/redmine_test.sqlite3
14 changes: 14 additions & 0 deletions docker-compose.mysql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.4'
services:
db:
image: mysql:${DB_VERSION:-latest}
environment:
MYSQL_ROOT_PASSWORD: password
volumes:
- mysql_data:/var/lib/mysql
ports:
- "3306:3306"


volumes:
mysql_data:
15 changes: 15 additions & 0 deletions docker-compose.postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.4'
services:
db:
image: postgres:${DB_VERSION:-latest}
volumes:
- postgres_data:/var/lib/postgresql
ports:
- "5432:5432"
environment:
LANG: C.UTF-8
POSTGRES_INITDB_ARGS: --locale=C.UTF-8
POSTGRES_PASSWORD: postgres

volumes:
postgres_data:
Loading