Skip to content

Commit

Permalink
Merge pull request #67 from true-runes/development
Browse files Browse the repository at this point in the history
v0.7.0
nikukyugamer authored Jun 19, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 71305ea + 7c3c77e commit 84a2780
Showing 13 changed files with 220 additions and 75 deletions.
60 changes: 0 additions & 60 deletions .github/workflows/gss2020_backend.yml

This file was deleted.

73 changes: 73 additions & 0 deletions .github/workflows/gss2022_backend_on_built_in_postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: 幻水総選挙2022 バックエンド

on:
push:
workflow_dispatch:

jobs:
gss2022_backend:
name: (pg on built-in) 継続的インテグレーション
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ["18.x"]
ruby-version: ["3.1"]
env:
CI: true
RAILS_ENV: test
POSTGRES_HOST_TEST: localhost
POSTGRES_PORT_TEST: 5432
POSTGRES_USERNAME_TEST: postgres_user
POSTGRES_PASSWORD_TEST: postgres_password
steps:
# https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-Readme.md
- name: PostgreSQL を起動する
run: |
sudo systemctl start postgresql.service
- name: PostgreSQL の起動待ち(ヘルスチェック)をする
run: |
until : > /dev/tcp/localhost/5432; do
echo -n .
sleep 1
done
echo 'PostgreSQL の起動が確認できました'
- name: PostgreSQL のユーザー(ロール)のセットアップを行う
# NOTE: バージョン番号が埋め込みになっているのが良くない
run: |
sudo bash -c "echo \"local all all md5\" >> /etc/postgresql/$major_version_number/main/pg_hba.conf"
sudo su postgres -c "psql postgres -c 'create role $username;'"
sudo su postgres -c "psql postgres -c \"alter role $username with login password '$password';\""
sudo su postgres -c "psql postgres -c \"alter role $username with superuser\""
env:
major_version_number: 14
username: postgres_user
password: postgres_password
- name: コードをチェックアウトする
uses: actions/checkout@v3
- name: Ruby のセットアップを行う
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
- name: $ bundle install を行う
uses: actions/cache@v3
with:
path: vendor/bundle
key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gem-
- name: (予定地)Node.js のセットアップを行う
run: |
echo 'Node.js を使うことがあれば "actions/setup-node" を用いる'
echo 'uses: actions/setup-node@v3'
echo 'with:'
echo 'node-version: ${{ matrix.node-version }}'
echo 'cache: "yarn"'
- name: データベースをセットアップする
run: |
bin/rails db:prepare
- name: RSpec を実行する
run: |
bundle exec rspec
62 changes: 62 additions & 0 deletions .github/workflows/gss2022_backend_on_postgres_services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: 幻水総選挙2022 バックエンド

on:
push:
workflow_dispatch:

jobs:
gss2022_backend:
name: (pg on services) 継続的インテグレーション
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ["18.x"]
ruby-version: ["3.1"]
services:
postgres:
image: postgres:14.3
ports:
- 5432:5432
env:
POSTGRES_USER: postgres_user
POSTGRES_PASSWORD: postgres_password
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
CI: true
RAILS_ENV: test
POSTGRES_HOST_TEST: localhost
POSTGRES_PORT_TEST: 5432
POSTGRES_USERNAME_TEST: postgres_user
POSTGRES_PASSWORD_TEST: postgres_password
steps:
- name: コードをチェックアウトする
uses: actions/checkout@v3
- name: Ruby のセットアップを行う
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
- name: $ bundle install を行う
uses: actions/cache@v3
with:
path: vendor/bundle
key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gem-
- name: (予定地)Node.js のセットアップを行う
run: |
echo 'Node.js を使うことがあれば "actions/setup-node" を用いる'
echo 'uses: actions/setup-node@v3'
echo 'with:'
echo 'node-version: ${{ matrix.node-version }}'
echo 'cache: "yarn"'
- name: データベースをセットアップする
run: |
bin/rails db:prepare
- name: RSpec を実行する
run: |
bundle exec rspec
2 changes: 1 addition & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--require spec_helper --format documentation
--require spec_helper --format documentation --force-color --backtrace
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
On PostgreSQL Services
[![幻水総選挙2022 バックエンド](https://github.com/true-runes/suikoden-election-2022-backend/actions/workflows/gss2022_backend_on_postgres_services.yml/badge.svg)](https://github.com/true-runes/suikoden-election-2022-backend/actions/workflows/gss2022_backend_on_postgres_services.yml)

On Built-In PostgreSQL
[![幻水総選挙2022 バックエンド](https://github.com/true-runes/suikoden-election-2022-backend/actions/workflows/gss2022_backend_on_built_in_postgres.yml/badge.svg)](https://github.com/true-runes/suikoden-election-2022-backend/actions/workflows/gss2022_backend_on_built_in_postgres.yml)

# 幻水総選挙2022(バックエンド)
- いつもの
51 changes: 46 additions & 5 deletions app/lib/twitter_rest_api.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,51 @@
class TwitterRestApi
def self.client(consumer_key: nil, consumer_secret: nil, access_token: nil, access_secret: nil)
# account_key は シンボル で指定する
def self.client(account_key: nil)
return if account_key.nil?

credentials = convert_account_key_to_credentials(account_key)
return if credentials.nil?

Twitter::REST::Client.new do |config|
config.consumer_key = consumer_key || ENV.fetch('TWITTER_CONSUMER_KEY', nil)
config.consumer_secret = consumer_secret || ENV.fetch('TWITTER_CONSUMER_SECRET', nil)
config.access_token = access_token || ENV.fetch('TWITTER_ACCESS_TOKEN', nil)
config.access_token_secret = access_secret || ENV.fetch('TWITTER_ACCESS_SECRET', nil)
config.consumer_key = credentials[:consumer_key]
config.consumer_secret = credentials[:consumer_secret]
config.access_token = credentials[:access_token]
config.access_token_secret = credentials[:access_token_secret]
end
end

def self.convert_account_key_to_credentials(account_key)
{
gensosenkyo: {
consumer_key: ENV.fetch('TWITTER_CONSUMER_KEY_GENSOSENKYO', nil),
consumer_secret: ENV.fetch('TWITTER_CONSUMER_SECRET_GENSOSENKYO', nil),
access_token: ENV.fetch('TWITTER_ACCESS_TOKEN_GENSOSENKYO', nil),
access_token_secret: ENV.fetch('TWITTER_ACCESS_SECRET_GENSOSENKYO', nil)
},
sub_gensosenkyo: {
consumer_key: ENV.fetch('TWITTER_CONSUMER_KEY_SUB_GENSOSENKYO', nil),
consumer_secret: ENV.fetch('TWITTER_CONSUMER_SECRET_SUB_GENSOSENKYO', nil),
access_token: ENV.fetch('TWITTER_ACCESS_TOKEN_SUB_GENSOSENKYO', nil),
access_token_secret: ENV.fetch('TWITTER_ACCESS_SECRET_SUB_GENSOSENKYO', nil)
},
tmytn: {
consumer_key: ENV.fetch('TWITTER_CONSUMER_KEY_TMYTN', nil),
consumer_secret: ENV.fetch('TWITTER_CONSUMER_SECRET_TMYTN', nil),
access_token: ENV.fetch('TWITTER_ACCESS_TOKEN_TMYTN', nil),
access_token_secret: ENV.fetch('TWITTER_ACCESS_SECRET_TMYTN', nil)
},
tmychan: {
consumer_key: ENV.fetch('TWITTER_CONSUMER_KEY_TMYCHAN', nil),
consumer_secret: ENV.fetch('TWITTER_CONSUMER_SECRET_TMYCHAN', nil),
access_token: ENV.fetch('TWITTER_ACCESS_TOKEN_TMYCHAN', nil),
access_token_secret: ENV.fetch('TWITTER_ACCESS_SECRET_TMYCHAN', nil)
},
ayy: {
consumer_key: ENV.fetch('TWITTER_CONSUMER_KEY_AYY', nil),
consumer_secret: ENV.fetch('TWITTER_CONSUMER_SECRET_AYY', nil),
access_token: ENV.fetch('TWITTER_ACCESS_TOKEN_AYY', nil),
access_token_secret: ENV.fetch('TWITTER_ACCESS_SECRET_AYY', nil)
}
}[account_key]
end
end
2 changes: 1 addition & 1 deletion app/models/tweet_on_tweet_storage.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class TweetOnTweetStorage < ApplicationRecord
establish_connection :tweet_storage
establish_connection :tweet_storage unless ENV['CI'] == 'true'

self.table_name = :tweets

2 changes: 1 addition & 1 deletion app/models/user_on_tweet_storage.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class UserOnTweetStorage < ApplicationRecord
establish_connection :tweet_storage
establish_connection :tweet_storage unless ENV['CI'] == 'true'

self.table_name = :users

5 changes: 5 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"config:base"
]
}
9 changes: 9 additions & 0 deletions spec/factories/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FactoryBot.define do
factory :user do
id_number { 192789663528910849 }
name { 'My name is test' }
screen_name { 'test_screen_name' }
profile_image_url_https { 'https://pbs.twimg.com/profile_images/1123471964058914816/a8sXngWB_400x400.png' }
is_protected { false }
end
end
7 changes: 0 additions & 7 deletions spec/misc/foo_spec.rb

This file was deleted.

15 changes: 15 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'rails_helper'

RSpec.describe User, type: :model do
let(:user) { create(:user) }

it 'User名が期待どおりに等しくあること' do
# expect(user.name).to eq 'My name is test'
# expect(User.count).to eq 1
end

it 'User名が期待どおりに等しくないこと' do
# expect(user.name).not_to eq 'Your name is test'
# expect(User.count).to eq 1
end
end
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -17,4 +17,5 @@
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
config.filter_rails_from_backtrace!
config.include FactoryBot::Syntax::Methods
end

0 comments on commit 84a2780

Please sign in to comment.