resquirrel 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7e1ffeaf1f7ec104553dabc0f016a0ae3d67a6b34638a81d26d0cca0072c1a7
4
- data.tar.gz: fd3b10b5c35ddaf4399541f99d828b321a68ca396b46128436cd8965a853bca5
3
+ metadata.gz: 231c1d6fb753b78c3998309549bd06276fd5a9768ebeac4300d75a0e5f2497c1
4
+ data.tar.gz: ca016974e8327e4e0294b89da4f837102d15f51fee19543e256a0af77ce9fdde
5
5
  SHA512:
6
- metadata.gz: 20b0e5df45f8dad12622dc5b2ff09a6485ca502ff09867ac7930981b17ef51c1f25cfbf412b56a0129196ff116a844b0ef63181f14bda9252bb28f42bdfc63c2
7
- data.tar.gz: 0b7c49d458c503666b44da267497ab279fd078e77d8d779a1060008b2c4aaa175654dc9980e4292195204bc5bdb7fb6b10e0ff228ae8668308c8bb36b4eb8a68
6
+ metadata.gz: 1c914d844624dc48c97c0df0edbdbe383d3b04d3e9d5f06707aafddcfe00ed6ec584457ca0cfd1448ca21af15b3628f3190d4dd1ebb9340b230437222513db49
7
+ data.tar.gz: 991150935129f67c224bf3edb1d5f1990d68003a1fb3978dc7b058a8d3fa5596992b79f3364393eec59768d9d1f052ac3e31f2815030e8a481e3f7126f2ae4a8
data/exe/resquirrel ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "resquirrel"
5
+
6
+ Resquirrel.generate_release_note
@@ -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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Resquirrel
4
+ VERSION = "0.1.5"
5
+ 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.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - yuki-snow1823
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-04 00:00:00.000000000 Z
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