resquirrel 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/exe/resquirrel +6 -0
- data/lib/client/notion.rb +41 -0
- data/lib/client/openai.rb +40 -0
- data/lib/resquirrel/version.rb +5 -0
- data/lib/resquirrel.rb +30 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 231c1d6fb753b78c3998309549bd06276fd5a9768ebeac4300d75a0e5f2497c1
|
4
|
+
data.tar.gz: ca016974e8327e4e0294b89da4f837102d15f51fee19543e256a0af77ce9fdde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c914d844624dc48c97c0df0edbdbe383d3b04d3e9d5f06707aafddcfe00ed6ec584457ca0cfd1448ca21af15b3628f3190d4dd1ebb9340b230437222513db49
|
7
|
+
data.tar.gz: 991150935129f67c224bf3edb1d5f1990d68003a1fb3978dc7b058a8d3fa5596992b79f3364393eec59768d9d1f052ac3e31f2815030e8a481e3f7126f2ae4a8
|
data/exe/resquirrel
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "net/http"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
class NotionClient
|
7
|
+
def initialize(api_key, database_id)
|
8
|
+
@api_key = api_key
|
9
|
+
@database_id = database_id
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_release_note(summary, url)
|
13
|
+
uri = URI("https://api.notion.com/v1/pages")
|
14
|
+
request = Net::HTTP::Post.new(uri)
|
15
|
+
request["Authorization"] = "Bearer #{@api_key}"
|
16
|
+
request["Notion-Version"] = "2022-06-28"
|
17
|
+
request.content_type = "application/json"
|
18
|
+
request.body = {
|
19
|
+
parent: { type: "database_id", database_id: @database_id },
|
20
|
+
properties: {
|
21
|
+
title: {
|
22
|
+
title: [
|
23
|
+
{
|
24
|
+
type: "text",
|
25
|
+
text: {
|
26
|
+
content: summary
|
27
|
+
}
|
28
|
+
}
|
29
|
+
]
|
30
|
+
},
|
31
|
+
URL: {
|
32
|
+
url: url
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}.to_json
|
36
|
+
|
37
|
+
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
38
|
+
http.request(request)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "net/http"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
class OpenAiClient
|
7
|
+
BASE_URL = "https://api.openai.com/v1"
|
8
|
+
|
9
|
+
def initialize(api_key, model: "gpt-3.5-turbo")
|
10
|
+
@api_key = api_key
|
11
|
+
@model = model
|
12
|
+
end
|
13
|
+
|
14
|
+
def summary_pr(title, body, max_tokens: 200)
|
15
|
+
uri = URI("#{BASE_URL}/chat/completions")
|
16
|
+
request = Net::HTTP::Post.new(uri)
|
17
|
+
request["Authorization"] = "Bearer #{@api_key}"
|
18
|
+
request.content_type = "application/json"
|
19
|
+
request.body = {
|
20
|
+
model: @model,
|
21
|
+
messages: [{ "role": "user",
|
22
|
+
"content":
|
23
|
+
"これからGitHub PRのタイトルと内容を送ります。
|
24
|
+
この内容を、プログラミングやウェブ技術にそれほど詳しくない人のために要約してください。
|
25
|
+
日本語で必ず返答してください。
|
26
|
+
要約の文章はタイトル:本文:のようにせず、文章だけでお願いします。
|
27
|
+
タイトルと本文を踏まえて、どのような変更があったのか文章にわかりやすくまとめてください。
|
28
|
+
以下がPRの内容です。
|
29
|
+
タイトル: #{title}
|
30
|
+
本文: #{body}" }],
|
31
|
+
max_tokens: max_tokens
|
32
|
+
}.to_json
|
33
|
+
|
34
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
35
|
+
http.request(request)
|
36
|
+
end
|
37
|
+
|
38
|
+
JSON.parse(response.body)
|
39
|
+
end
|
40
|
+
end
|
data/lib/resquirrel.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "resquirrel/version"
|
4
|
+
require_relative "client/openai"
|
5
|
+
require_relative "client/notion"
|
6
|
+
require "json"
|
7
|
+
require "logger"
|
8
|
+
|
9
|
+
module Resquirrel
|
10
|
+
def self.generate_release_note
|
11
|
+
openai_client = OpenAiClient.new(ENV["OPENAI_API_KEY"])
|
12
|
+
notion_client = NotionClient.new(ENV["NOTION_API_KEY"], ENV["NOTION_DATABASE_ID"])
|
13
|
+
logger = Logger.new($stdout)
|
14
|
+
|
15
|
+
logger.info "Getting PR information..."
|
16
|
+
pr_data = JSON.parse(File.read(ENV["GITHUB_EVENT_PATH"]))["pull_request"]
|
17
|
+
|
18
|
+
title = pr_data["title"]
|
19
|
+
body = pr_data["body"]
|
20
|
+
|
21
|
+
logger.info "Summarizing PR with OpenAI..."
|
22
|
+
response = openai_client.summary_pr(title, body)
|
23
|
+
|
24
|
+
summary = response["choices"].first["message"]["content"]
|
25
|
+
url = pr_data["html_url"]
|
26
|
+
|
27
|
+
logger.info "Updating Notion database..."
|
28
|
+
notion_client.create_release_note(summary, url)
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resquirrel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yuki-snow1823
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: RubyGems that automatically create release notes for Notion DB using
|
14
14
|
Open AI API when PR merge.
|
@@ -25,6 +25,11 @@ files:
|
|
25
25
|
- LICENSE.txt
|
26
26
|
- README.md
|
27
27
|
- Rakefile
|
28
|
+
- exe/resquirrel
|
29
|
+
- lib/client/notion.rb
|
30
|
+
- lib/client/openai.rb
|
31
|
+
- lib/resquirrel.rb
|
32
|
+
- lib/resquirrel/version.rb
|
28
33
|
homepage: https://github.com/yuki-snow1823/resquirrel
|
29
34
|
licenses:
|
30
35
|
- MIT
|