resquirrel 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d1b67d88a6d2613d99f17da16dbd88b207d4f8d73f53ac89ebc4e4baa9d97ece
4
+ data.tar.gz: 01c194ab3ac13bd585480877360bcdf595d3bc8694a2d6d1e81806df53800ada
5
+ SHA512:
6
+ metadata.gz: 3b73fe4ea5c9adf48c4db5b0a8f0c8a13f08859f454bb302bfdb69fece539799adab9e7175748110385ed026bc5f69fbb40ae898f3429fb8c265592349cc300b
7
+ data.tar.gz: f26a0c8c04e737cc5bc1ecd37ad870984f1859166b7de1232fa7e03b6cb5af8471fbfea839091cc1db7bb8d89736fe44252cc41123b27fd94053260b590a09bd
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,28 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Metrics/MethodLength:
16
+ Max: 30
17
+
18
+ Metrics/AbcSize:
19
+ Max: 20
20
+
21
+ Style/Documentation:
22
+ Enabled: false
23
+
24
+ Layout/TrailingWhitespace:
25
+ Enabled: false
26
+
27
+ Layout/SpaceInsideHashLiteralBraces:
28
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-04-23
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at y.horikoshi.pg@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 yuki-snow1823
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,169 @@
1
+ # Resquirrel
2
+
3
+ RubyGems that automatically create release notes for Notion DB using Open AI API.
4
+
5
+ <img width="480" src="https://github.com/yuki-snow1823/resquirrel/assets/59280290/48ab260d-242b-421d-b7ce-88ba611f0d19">
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```Gemfile
13
+ gem 'fabrique'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ ```console
19
+ $ bundle install
20
+ ```
21
+
22
+ Or install it yourself as:
23
+
24
+ ```console
25
+ $ gem install resquirrel
26
+ ```
27
+
28
+ ## Usage(日本語)
29
+
30
+ ### NotionのAPIキーの用意
31
+ 1. まずは、NotionのAPIを使えるようにするためのトークンを取得します。
32
+ 2. [Notionの開発者ページ](https://www.notion.so/my-integrations)にアクセスします。
33
+ 3. `New integration`をクリックして、作成したトークンをリリースノートを作成したいリポジトリのrepository secretsに登録します。`NOTION_API_KEY`という名前で登録してください。
34
+
35
+ ### Notionのデータベースの用意
36
+ 1. Notionにリリースノートを作成するためのFull Pageのデータベースを作成します。
37
+ 2. データベースには、以下のプロパティを用意します。
38
+ - `changes` : リリースノートのタイトル(DBを作成するとデフォルトで用意されています。)
39
+ - `URL` : リリースノートのリンク
40
+ 3. 作成したDBのURLをコピーして、https://www.notion.so/[この部分]?v=hogehoge の文字列を、リリースノートを作成したいリポジトリのrepository secretsに登録します。`NOTION_DATABASE_ID`という名前で登録してください。
41
+
42
+ ### Open AI APIの用意
43
+ 1. Open AI APIを使えるようにするためのAPIキーを取得します。
44
+ 2. [Open AIの開発者ページ](https://platform.openai.com/account/api-keys)にアクセスします。
45
+ 3. `Create API Key`をクリックして、作成したAPIキーをリリースノートを作成したいリポジトリのrepository secretsに登録します。`OPENAI_API_KEY`という名前で登録してください。
46
+ - 制限に関しては、ModelsのRead、Model CapabilitiesのWriteが必要です。
47
+
48
+ ### 実行方法
49
+ sample:
50
+ `.github/workflows/create_release_notes.yml` のようなCIで実行するファイルを作成します。
51
+
52
+ ```yml
53
+ name: create release notes
54
+
55
+ on:
56
+ pull_request:
57
+ types:
58
+ - closed
59
+
60
+ jobs:
61
+ create_release_notes:
62
+ if: ${{ github.event.pull_request.merged }}
63
+ runs-on: ubuntu-latest
64
+
65
+ steps:
66
+ - name: Checkout code
67
+ uses: actions/checkout@v3
68
+
69
+ - name: Set up Ruby
70
+ uses: ruby/setup-ruby@v1
71
+ with:
72
+ ruby-version: '3.3'
73
+
74
+ - name: Install dependencies
75
+ run: |
76
+ bundle install
77
+
78
+ - name: Run script
79
+ run: ruby lib/resquirrel.rb
80
+ env:
81
+ GITHUB_EVENT_PATH: ${{ github.event_path }}
82
+ OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
83
+ NOTION_API_KEY: ${{ secrets.NOTION_API_KEY }}
84
+ NOTION_DATABASE_ID: ${{ secrets.NOTION_DATABASE_ID }}
85
+ ```
86
+
87
+ ```rb
88
+ resquirrel = Resquirrel.new
89
+ resquirrel.generate_release_note
90
+ ```
91
+ それぞれのenvは必須です。
92
+
93
+ ## Usage(English)
94
+
95
+ ### Preparing Notion's API key
96
+ 1. first, you will need to obtain a token to be able to use Notion's API. 2.
97
+ 2. go to [Notion's developer page](https://www.notion.so/my-integrations).
98
+ 3. click `New integration` and register the token you have created in the repository secrets of the repository for which you want to create release notes. The name shold be set `NOTION_API_KEY`.
99
+
100
+ ### Preparing Notion's database
101
+ 1. Create a Full Page database in Notion to create release notes.
102
+ 2. Prepare the following properties in the database.
103
+ - `changes` : Title of the release note (this is provided by default when you create a DB.)
104
+ - `URL` : Link to the release note
105
+ 3. Copy the URL of the created DB and register the string `https://www.notion.so/[this part]?v=hogehoge` in the repository secrets of the repository where you want to create the release notes. The name should be set to `NOTION_DATABASE_ID`.
106
+
107
+ ### Preparing Open AI API
108
+ 1. Obtain an API key to use the Open AI API.
109
+ 2. Go to the [Open AI developer page](https://platform.openai.com/account/api-keys).
110
+ 3. Click `Create API Key` and register the created API key in the repository secrets of the repository where you want to create the release notes. The name should be set to `OPENAI_API_KEY`.
111
+ - The required permissions are Models Read and Model Capabilities Write.
112
+
113
+ ### How to run
114
+ sample:
115
+ Create a file to run the script in CI, such as `.github/workflows/create_release_notes.yml`.
116
+
117
+
118
+ ```yml
119
+ name: create release notes
120
+
121
+ on:
122
+ pull_request:
123
+ types:
124
+ - closed
125
+
126
+ jobs:
127
+ create_release_notes:
128
+ if: ${{ github.event.pull_request.merged }}
129
+ runs-on: ubuntu-latest
130
+
131
+ steps:
132
+ - name: Checkout code
133
+ uses: actions/checkout@v3
134
+
135
+ - name: Set up Ruby
136
+ uses: ruby/setup-ruby@v1
137
+ with:
138
+ ruby-version: '3.3'
139
+
140
+ - name: Install dependencies
141
+ run: |
142
+ bundle install
143
+
144
+ - name: Run script
145
+ run: ruby lib/resquirrel.rb
146
+ env:
147
+ GITHUB_EVENT_PATH: ${{ github.event_path }}
148
+ OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
149
+ NOTION_API_KEY: ${{ secrets.NOTION_API_KEY }}
150
+ NOTION_DATABASE_ID: ${{ secrets.NOTION_DATABASE_ID }}
151
+ ```
152
+
153
+ ```rb
154
+ resquirrel = Resquirrel.new
155
+ resquirrel.generate_release_note
156
+ ```
157
+ Each env is required.
158
+
159
+ ## Contributing
160
+
161
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yuki-snow1823/resquirrel This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/yuki-snow1823/resquirrel/blob/main/CODE_OF_CONDUCT.md).
162
+
163
+ ## License
164
+
165
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
166
+
167
+ ## Code of Conduct
168
+
169
+ Everyone interacting in the Resquirrel project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yuki-snow1823/resquirrel/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -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,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "logger"
4
+ require "json"
5
+ require_relative "client/notion"
6
+ require_relative "client/openai"
7
+
8
+ class Resquirrel
9
+ def initialize
10
+ @openai_client = OpenAiClient.new(ENV["OPENAI_API_KEY"])
11
+ @notion_client = NotionClient.new(ENV["NOTION_API_KEY"], ENV["NOTION_DATABASE_ID"])
12
+ end
13
+
14
+ def generate_release_note
15
+ logger = Logger.new($stdout)
16
+
17
+ logger.info "Getting PR information..."
18
+ pr_data = JSON.parse(File.read(ENV["GITHUB_EVENT_PATH"]))["pull_request"]
19
+
20
+ title = pr_data["title"]
21
+ body = pr_data["body"]
22
+
23
+ logger.info "Summarizing PR with OpenAI..."
24
+ response = @openai_client.summary_pr(title, body)
25
+
26
+ summary = response["choices"].first["message"]["content"]
27
+ url = pr_data["html_url"]
28
+
29
+ logger.info "Updating Notion database..."
30
+ @notion_client.create_release_note(summary, url)
31
+ end
32
+ end
33
+
34
+ resquirrel = Resquirrel.new
35
+ resquirrel.generate_release_note
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Resquirrel
4
+ VERSION = "0.1.0"
5
+ end
data/lib/resquirrel.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "resquirrel/version"
4
+
5
+ module Resquirrel
6
+ class Error < StandardError; end
7
+ # Your code goes here...
8
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resquirrel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - yuki-snow1823
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-04-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ''
14
+ email:
15
+ - y.horikoshi.pg@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rspec"
21
+ - ".rubocop.yml"
22
+ - CHANGELOG.md
23
+ - CODE_OF_CONDUCT.md
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - lib/resquirrel.rb
28
+ - lib/resquirrel/client/notion.rb
29
+ - lib/resquirrel/client/openai.rb
30
+ - lib/resquirrel/main.rb
31
+ - lib/resquirrel/version.rb
32
+ homepage: https://github.com/yuki-snow1823/resquirrel
33
+ licenses:
34
+ - MIT
35
+ metadata:
36
+ homepage_uri: https://github.com/yuki-snow1823/resquirrel
37
+ source_code_uri: https://github.com/yuki-snow1823/resquirrel
38
+ changelog_uri: https://github.com/yuki-snow1823/resquirrel/blob/main/CHANGELOG.md
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.6.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.5.3
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: RubyGems that automatically create release notes for Notion DB using Open
58
+ AI API.
59
+ test_files: []