Skip to content

Commit f43ccb3

Browse files
authored
Merge pull request #98 from nakkaa/release_v1.0.4
Release v1.0.4
2 parents 4f910d5 + dc51615 commit f43ccb3

28 files changed

+305
-80
lines changed

.github/workflows/pr-test.yml

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,74 @@ jobs:
107107
python -m pip install --upgrade pip
108108
pip install pipenv
109109
pipenv install --dev
110+
- name: Set .env
111+
run: |
112+
cp .env.example .env
110113
- name: Test
111114
run: |
112115
pipenv run python -m unittest
113116
117+
# 型ヒントのチェックを行う
118+
pr-type-hint:
119+
runs-on: ubuntu-latest
120+
strategy:
121+
matrix:
122+
python-version: [3.8]
123+
124+
steps:
125+
- uses: actions/checkout@v2
126+
- name: pipenv cache
127+
uses: actions/cache@v1
128+
with:
129+
key: ${{ runner.os }}-${{ matrix.python-version }}-pipenv-${{ hashFiles('**/Pipfile.lock') }}
130+
path: ~/.cache/pipenv
131+
restore-keys: |
132+
${{ runner.os }}-${{ matrix.python-version }}-pipenv-
133+
- name: pip cache
134+
uses: actions/cache@v1
135+
with:
136+
path: ~/.cache/pip
137+
key: ${{ runner.os }}-pip-${{ hashFiles('**/Pipfile.lock') }}
138+
restore-keys: |
139+
${{ runner.os }}-pip-
140+
- name: Set up Python ${{ matrix.python-version }}
141+
uses: actions/setup-python@v1
142+
with:
143+
python-version: ${{ matrix.python-version }}
144+
- name: Install dependencies
145+
run: |
146+
python -m pip install --upgrade pip
147+
pip install pipenv
148+
pipenv install --dev
149+
- name: Check type hints
150+
run: |
151+
pipenv run mypy .
152+
153+
# 差分があるPythonファイルを取得する
154+
pr-check-python-files-with-diff:
155+
runs-on: ubuntu-latest
156+
157+
outputs:
158+
files: ${{steps.check-python-files-with-diff.outputs.files}}
159+
160+
steps:
161+
- uses: actions/checkout@v2
162+
with:
163+
fetch-depth: 0
164+
- name: Check Python file with diff
165+
id: check-python-files-with-diff
166+
run: |
167+
git fetch --no-tags --prune --depth=1 origin ${GITHUB_HEAD_REF}
168+
git fetch --no-tags --prune --depth=1 origin ${GITHUB_BASE_REF}
169+
echo "::set-output name=files::$(git diff origin/${GITHUB_BASE_REF}..origin/${GITHUB_HEAD_REF} --diff-filter=AM --name-only -- '*.py' | tr '\n' ' ')"
170+
114171
# lintを行い、結果をPRにコメントとして表示する。
115172
# ここではチェックは落ちない
116173
pr-lint:
117174
runs-on: ubuntu-latest
175+
needs: pr-check-python-files-with-diff
176+
# Pythonファイルが差分に含まれていない場合はスキップ
177+
if: needs.pr-check-python-files-with-diff.outputs.files != ''
118178
strategy:
119179
matrix:
120180
python-version: [3.8]
@@ -151,9 +211,7 @@ jobs:
151211
- name: Lint files
152212
id: lint
153213
run: |
154-
git fetch --no-tags --prune --depth=1 origin ${GITHUB_HEAD_REF}
155-
git fetch --no-tags --prune --depth=1 origin ${GITHUB_BASE_REF}
156-
result=$(pipenv run pylint --rcfile=./.pylintrc $(git diff origin/${GITHUB_BASE_REF}..origin/${GITHUB_HEAD_REF} --diff-filter=AM --name-only -- '*.py') 2>&1) || true
214+
result=$(pipenv run pylint --rcfile=./.pylintrc ${{needs.pr-check-python-files-with-diff.outputs.files}} 2>&1) || true
157215
result="${result//'%'/'%25'}"
158216
result="${result//$'\n'/'%0A'}"
159217
result="${result//$'\r'/'%0D'}"
@@ -162,6 +220,7 @@ jobs:
162220
continue-on-error: true
163221
# lint結果をコメントに残す
164222
- name: Lint Comment
223+
if: steps.lint.outputs.result != ''
165224
uses: actions/github-script@0.9.0
166225
with:
167226
github-token: ${{secrets.GITHUB_TOKEN}}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
__pycache__/
44
.vscode/
55
setup/pgsql-data
6+
.mypy_cache/

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ signature-mutators=
445445
expected-line-ending-format=
446446

447447
# Regexp for a line that is allowed to be longer than the limit.
448-
ignore-long-lines=^\s*(# )?<?https?://\S+>?$
448+
ignore-long-lines=^\s*((# )?<?https?://\S+>?|(from .* )?import .*)$
449449

450450
# Number of spaces of indent required inside a hanging or continued line.
451451
indent-after-paren=4

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
* `Removed` 削除された機能について。
88
* `Fixed` バグ修正について。
99

10+
## v1.0.4 - 2020-06-06
11+
### Changed
12+
* DockerのpostgresqlもSSLに対応しました。(#66)
13+
* Readmeに機能説明とTokenを発行する手順ページのリンクを追加しました。(#78)
14+
* 天気コマンドを入力したときに全角スペースでも反応するように修正しました。(#80)
15+
16+
### Removed
17+
* `amesh kyoto` コマンドは削除されました。(#83)
18+
19+
1020
## v1.0.3 - 2020-05-23
1121
### Added
1222
* Botのアイコン画像を同梱しました。(#46)

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ requests = "==2.23.0"
1313
slackbot = "==0.5.6"
1414
Pillow = ">=7.1.2"
1515
pg8000 = "==1.15.2"
16+
mypy = "*"
1617

1718
[requires]
1819
python_version = "3.8"

Pipfile.lock

Lines changed: 71 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
1-
# 鳩bot
1+
# 鳩bot - 愛嬌のあるSlack Bot
22
![](https://github.com/nakkaa/hato-bot/workflows/pr-test/badge.svg) [![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=nakkaa/hato-bot)](https://dependabot.com)
3+
34
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)
45

5-
- 愛嬌のあるSlack用botです。
6-
- `天気 <地名>` で天気予報を教えてくれます。
7-
- `amesh` で東京近郊の雨雲情報を教えてくれます。
8-
- `>< 文字列` で文字列を「突然の死」吹き出しで整形してくれます。
6+
鳩botではこんなことができます。
7+
8+
- 全国の天気予報 ... `天気 東京` で東京の天気予報を表示します。
9+
- 東京近郊の雨雲情報 ... `amesh` で東京の雨雲情報を画像で表示します。
10+
- 最新の地震情報 ... `eq` で最新の地震情報を3件表示します。
11+
- パワーワードの登録、表示 ... `text` で登録したパワーワードを表示します。
12+
- 突然の死吹き出しで整形 ... `>< 文字列` で文字列を「突然の死」吹き出しで整形します。
913

1014
![](https://github.com/nakkaa/hato-age-bot/blob/images/hato1.png)
1115

16+
# 鳩botを動かす
17+
18+
鳩botを動かす方法は主に2種類あります。
19+
簡単でおすすめなHerokuで動かす方法と自分のPC上で動かす方法です。
20+
前者については、[Herokuで動かす手順](https://github.com/nakkaa/hato-bot/wiki/Heroku%E3%81%A7%E5%8B%95%E3%81%8B%E3%81%99%E6%89%8B%E9%A0%86) を参照してください。
21+
ここでは後者の自分のPC上で動かす方法を説明します。
22+
1223
## 必要なもの
13-
鳩botを動かすためには以下が必要です。
14-
- Python3
15-
- PostgreSQL(Dockerで導入可)
24+
以下が必要です。
25+
- Git、Python3、Pipenv、Docker(またはPostgreSQL)が動作するPC
26+
- Slack API Token ([Slack API Tokenの取得方法](https://github.com/nakkaa/hato-bot/wiki/Slack-API-Token%E3%81%AE%E5%8F%96%E5%BE%97%E6%96%B9%E6%B3%95))
27+
- Yahoo APIのトークン([Yahoo API Tokenの取得方法](https://github.com/nakkaa/hato-bot/wiki/Yahoo-API-Token%E3%81%AE%E5%8F%96%E5%BE%97%E6%96%B9%E6%B3%95))
1628

1729
## 初期設定
1830

@@ -27,7 +39,7 @@
2739
pipenv install
2840
```
2941
30-
3. `.env` ファイルを作成し、SlackのAPI TokenとPostgreSQLの認証情報、(雨雲情報を取得する場合は)Yahoo APIのトークンを記述します
42+
3. `.env` ファイルを作成し Slack API Token、PostgreSQLの認証情報、Yahoo API Tokenを記述します
3143
```
3244
SLACKBOT_API_TOKEN=xoxb_xxxxxxxxx
3345
DATABASE_URL=postgres://postgres:password@localhost:5432/
@@ -45,6 +57,11 @@
4557
4658
6. `pipenv run python ./run.py` を実行します。
4759
48-
## formatする
60+
## 補足
61+
62+
- コードをformatする場合は `pipenv run autopep8 --in-place --recursive .` を実行します。
63+
64+
## クレジット
65+
Botで利用しているサービスのクレジットを記載します。
4966
50-
1. `pipenv run autopep8 --in-place --recursive .`
67+
- [Web Services by Yahoo! JAPAN](https://developer.yahoo.co.jp/about)

create_env.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,35 @@ def __init__(self):
2626
def __enter__(self):
2727
return self
2828

29-
def execute_sql(self, SQL) -> str:
29+
def execute_sql(self, sql: str) -> None:
30+
"""SQLを実行する"""
31+
3032
with self.conn.cursor() as cursor:
3133
try:
32-
cursor.execute(SQL)
34+
cursor.execute(sql)
3335
self.conn.commit()
34-
print('Create table. {}'.format(SQL))
35-
except:
36+
print('Create table. {}'.format(sql))
37+
except Exception as _e:
3638
print('Can not execute sql(create_table).')
39+
raise _e
3740

3841
def __exit__(self, exc_type, exc_value, traceback):
3942
self.conn.close()
4043

4144

42-
def create_table():
43-
with CreateEnvDatabase() as db:
44-
db.execute_sql(
45+
def create_table() -> None:
46+
"""テーブルを作成する"""
47+
48+
with CreateEnvDatabase() as _db:
49+
_db.execute_sql(
4550
"CREATE TABLE IF NOT EXISTS vocabulary(no serial UNIQUE, word text);")
46-
db.execute_sql(
51+
_db.execute_sql(
4752
"CREATE TABLE IF NOT EXISTS labotter(user_name text UNIQUE, lab_in_flag int, lab_in timestamp, lab_rida timestamp, min_sum int);")
4853

4954

5055
def main():
56+
"""メイン関数"""
57+
5158
create_table()
5259

5360

0 commit comments

Comments
 (0)