newsman 0.1.0
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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/bin/newsman +5 -0
- data/lib/newsman/pull_request.rb +13 -0
- data/lib/newsman.rb +136 -0
- data/test/newsman/test_week_before.rb +31 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bbdbadb8ae1727aa56b52deae928ceb16d0068d9b0190ac2672a75a98c669231
|
4
|
+
data.tar.gz: 5b0487e709dd265cfcfe39ffadab3ac1bff14fd0e94ad547fb49aa56567e317d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 749af2c2ce1a20006ad4ba4373c2d53f0f52c604c8f9801acb87f6f2cd6bd421d79690e643e46b5c97fad09a80a7ea75e41db8e6e4523da689c07025d0e0b059
|
7
|
+
data.tar.gz: 68e39b6efe454c926b8164e4c3c7e7fe6682c6086f80b0a579a84cc3116df2f424c2bad1f8572d2466bf07f8fc6c3b703c9325fa295eba028b229935c53535b9
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Volodya Lombrozo
|
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
|
13
|
+
in 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 NON-INFRINGEMENT. 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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Newsman
|
2
|
+
|
3
|
+
Newsman is a simple script that collects information about a developer's weekly activity on GitHub and creates a human-readable summary of the work done. To create the summary, Newsman asks ChatGPT to handle all the information about a developer's activity, including their pull requests and created issues.
|
4
|
+
|
5
|
+
## How to Use
|
6
|
+
|
7
|
+
To use newsman, you need to perfom several actions.
|
8
|
+
|
9
|
+
### Retrieve `GITHUB_TOKEN`
|
10
|
+
|
11
|
+
First of all, you need to [retrieve your GitHub token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens).
|
12
|
+
|
13
|
+
### Retrieve `OPENAI_TOKEN`
|
14
|
+
|
15
|
+
Then, you need to [set up your OpenAI key](https://platform.openai.com/docs/quickstart?context=curl).
|
16
|
+
|
17
|
+
## Run the script
|
18
|
+
|
19
|
+
To run the newsman script you should pass `GITHUB_TOKEN` and `OPENAI_TOKEN` environment variables together with `name`, `username` and `repository` parameters.
|
20
|
+
If you have some problems you can use `--help` option to get more info about newsman usage:
|
21
|
+
```shell
|
22
|
+
Usage: newsman [options]
|
23
|
+
-n, --name NAME Reporter name. Human readable name that will be used in a report
|
24
|
+
-u, --username USERNAME GitHub username. For example, 'volodya-lombrozo'
|
25
|
+
-r, --repository REPOSITORIES Specify which repositories to include in a report. You can specify several repositories using a comma separator, for example: '-r objectionary/jeo-maven-plugin,objectionary/opeo-maven-plugin'
|
26
|
+
-p, --position Reporter position in a company. Default value is a 'Software Developer'.
|
27
|
+
```
|
28
|
+
|
29
|
+
### Example
|
30
|
+
|
31
|
+
You can download this repository and run the newsman script directly using the following command:
|
32
|
+
```shell
|
33
|
+
./bin/newsman --name "Vladimir Zakharov" --username "volodya-lombrozo" --repository objectionary/jeo-maven-plugin,objectionary/opeo-maven-plugin
|
34
|
+
```
|
35
|
+
|
36
|
+
Don't forget to set your own values for `name`, `username` and `repository` parameters.
|
37
|
+
|
38
|
+
## How to build a gem from sources
|
39
|
+
|
40
|
+
To create a newsman gem from sources first of all you need to build it:
|
41
|
+
```shell
|
42
|
+
gem build newsman.gemspec
|
43
|
+
```
|
44
|
+
Then, in the folder you might find a newly created gem file, e.g `newsman-0.1.0.gem`.
|
45
|
+
To use it in any place of your system you need to install it:
|
46
|
+
```shell
|
47
|
+
gem install newsman-0.1.0.gem
|
48
|
+
```
|
49
|
+
To check that everythis is fine, just run the following command:
|
50
|
+
```
|
51
|
+
newsman --help
|
52
|
+
```
|
53
|
+
Annd you should see a welcome message from newsman.
|
data/bin/newsman
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
class PullRequest
|
2
|
+
attr_accessor :repository, :title, :description
|
3
|
+
|
4
|
+
def initialize(repository, title, description)
|
5
|
+
@repository = repository
|
6
|
+
@title = title
|
7
|
+
@description = description
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
"title: ```#{@title}```\n, description: ```#{@description}```\n, repo: ```#{@repository}```\n"
|
12
|
+
end
|
13
|
+
end
|
data/lib/newsman.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'octokit'
|
4
|
+
require 'openai'
|
5
|
+
require 'dotenv'
|
6
|
+
require 'optparse'
|
7
|
+
require_relative 'newsman/pull_request.rb'
|
8
|
+
|
9
|
+
def generate
|
10
|
+
# Load all options required
|
11
|
+
# Pay attention that some of them have default values.
|
12
|
+
options = {}
|
13
|
+
OptionParser.new do |opts|
|
14
|
+
opts.banner = "Usage: newsman [options]"
|
15
|
+
opts.on("-n", "--name NAME", "Reporter name. Human readable name that will be used in a report") do |n|
|
16
|
+
options[:name] = n
|
17
|
+
end
|
18
|
+
opts.on("-u", "--username USERNAME", "GitHub username. For example, 'volodya-lombrozo'") do |u|
|
19
|
+
options[:username] = u
|
20
|
+
end
|
21
|
+
opts.on("-r", "--repository REPOSITORIES", "Specify which repositories to include in a report. You can specify several repositories using a comma separator, for example: '-r objectionary/jeo-maven-plugin,objectionary/opeo-maven-plugin'") do |r|
|
22
|
+
options[:repositories] = r
|
23
|
+
end
|
24
|
+
opts.on("-p", "--position", "Reporter position in a company. Default value is a 'Software Developer'.") do |p|
|
25
|
+
options[:position] = p
|
26
|
+
end
|
27
|
+
end.parse!
|
28
|
+
# Custom method to raise exception with a human-readable message
|
29
|
+
def options.require_option(key, message)
|
30
|
+
raise OptionParser::MissingArgument, message if self[key].nil?
|
31
|
+
end
|
32
|
+
|
33
|
+
# Check for required options
|
34
|
+
options.require_option(:name, "Reporter name is required. Please specify using -n or --name.")
|
35
|
+
options.require_option(:username, "GitHub username is required. Please specify using -u or --username.")
|
36
|
+
options.require_option(:repositories, "GitHub repository is required. Please specify one or several repositories using -r or --repositories.")
|
37
|
+
options[:position] ||= "Software Developer"
|
38
|
+
all_params = options.map { |key, value| "#{key}: #{value}" }.join(", ")
|
39
|
+
puts "Parsed parameters: #{all_params}"
|
40
|
+
|
41
|
+
# Load all required environment variables
|
42
|
+
Dotenv.load
|
43
|
+
Dotenv.require_keys("GITHUB_TOKEN", "OPENAI_TOKEN")
|
44
|
+
|
45
|
+
# Init all required parameters
|
46
|
+
# Reporter Info
|
47
|
+
reporter = options[:name]
|
48
|
+
reporter_position = options[:position]
|
49
|
+
# GitHub
|
50
|
+
github_username = options[:username]
|
51
|
+
github_repositories = options[:repositories].split(",").map { |repo| "repo:" + repo }.join(" ")
|
52
|
+
|
53
|
+
# Your GitHub personal access token
|
54
|
+
# Make sure it has the 'repo'
|
55
|
+
github_token = ENV['GITHUB_TOKEN']
|
56
|
+
# Your OpenAI personal access token
|
57
|
+
openai_token = ENV['OPENAI_TOKEN']
|
58
|
+
# Create a GitHub client instance with your access token
|
59
|
+
client = Octokit::Client.new(github_token: github_token)
|
60
|
+
# Calculate the date one week ago
|
61
|
+
report_date = Date.today
|
62
|
+
one_week_ago = date_one_week_ago(Date.today)
|
63
|
+
# Display pull request
|
64
|
+
query = "is:pr author:#{github_username} created:>=#{one_week_ago} #{github_repositories}"
|
65
|
+
puts "Searching pull requests for #{github_username}."
|
66
|
+
puts "Newsman uses the following request to GitHub to gather the required information about user activity: '#{query}'"
|
67
|
+
prs = []
|
68
|
+
pull_requests = client.search_issues(query)
|
69
|
+
pull_requests.items.each do |pr|
|
70
|
+
title = "#{pr.title}"
|
71
|
+
description = "#{pr.body}"
|
72
|
+
repository = pr.repository_url.split('/').last
|
73
|
+
puts "Found PR in #{repository}: #{title}"
|
74
|
+
# Create a new PullRequest object and add it to the list
|
75
|
+
pr = PullRequest.new(repository, title, description)
|
76
|
+
prs << pr
|
77
|
+
end
|
78
|
+
puts "\nNow lets test some aggregation using OpenAI\n\n"
|
79
|
+
openai_client = OpenAI::Client.new(access_token: openai_token)
|
80
|
+
example = "Last week achievements.
|
81
|
+
jeo-meven-plugin:
|
82
|
+
- Added 100 new files to the Dataset [#168]
|
83
|
+
- Fixed the deployment of XYZ [#169]
|
84
|
+
- Refined the requirements [#177]
|
85
|
+
opeo-maven-plugin
|
86
|
+
- Removed XYZ class [#57]
|
87
|
+
- Refactored http module [#69]
|
88
|
+
|
89
|
+
Next week plans:
|
90
|
+
jeo-maven-plugin:
|
91
|
+
- <leave empty>
|
92
|
+
opeo-maven-plugin:
|
93
|
+
- <leave empty>
|
94
|
+
|
95
|
+
Risks:
|
96
|
+
jeo-maven-plugin:
|
97
|
+
- <leave-empty>
|
98
|
+
opeo-maven-plugin:
|
99
|
+
- <leave-empty>
|
100
|
+
|
101
|
+
Best regards,
|
102
|
+
#{reporter}
|
103
|
+
#{reporter_position}
|
104
|
+
#{report_date}
|
105
|
+
"
|
106
|
+
|
107
|
+
response = openai_client.chat(
|
108
|
+
parameters: {
|
109
|
+
model: "gpt-3.5-turbo",
|
110
|
+
messages: [
|
111
|
+
{ role: "system", content: "You are a developer tasked with composing a concise report detailing your activities and progress for the previous week, intended for submission to your supervisor."},
|
112
|
+
{ role: "user", content: "Please compile a summary of the work completed in the following Pull Requests (PRs). Each PR should be summarized in a single sentence, focusing more on the PR title and less on implementation details. Group the sentences by repositories, each identified by its name mentioned in the 'repository:[name]' attribute of the PR. The grouping is important an should be precise. Ensure that each sentence includes the corresponding issue number as an integer value. If a PR doesn't mention an issue number, just print [#chore]. Combine all the information from each PR into a concise and fluent sentence, as if you were a developer reporting on your work. Please strictly adhere to the example template provided. Example of a report: #{example}. List of Pull Requests: [#{prs}]"}
|
113
|
+
],
|
114
|
+
temperature: 0.3,
|
115
|
+
})
|
116
|
+
puts response.dig("choices", 0, "message", "content")
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
def date_one_week_ago(today)
|
121
|
+
# Convert today to a Date object if it's not already
|
122
|
+
today = Date.parse(today) unless today.is_a?(Date)
|
123
|
+
# Subtract 7 days to get the date one week ago
|
124
|
+
one_week_ago = today - 7
|
125
|
+
# Format the date as "YYYY-MM-DD"
|
126
|
+
formatted_date = one_week_ago.strftime("%Y-%m-%d")
|
127
|
+
# Return the formatted date
|
128
|
+
return formatted_date
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
# Execute the function only if this script is run directly like `./newsman.rb`
|
133
|
+
if __FILE__ == $0
|
134
|
+
generate()
|
135
|
+
end
|
136
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Copyright (c) 2024 Volodya Lombrozo
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
+
# SOFTWARE.
|
21
|
+
|
22
|
+
require 'minitest/autorun'
|
23
|
+
require_relative '../../lib/newsman/newsman.rb'
|
24
|
+
|
25
|
+
class TestDateOneWeekAgo < Minitest::Test
|
26
|
+
def test_date_one_week_ago
|
27
|
+
assert_equal "2024-03-07", date_one_week_ago(Date.new(2024, 3, 14))
|
28
|
+
assert_equal "2024-02-29", date_one_week_ago(Date.new(2024, 3, 7))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: newsman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Volodya Lombrozo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-03-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
description: A simple gem that gathers GitHub statistics and creates human-readable
|
28
|
+
report
|
29
|
+
email:
|
30
|
+
- volodya.lombrozo@gmail.com
|
31
|
+
executables:
|
32
|
+
- newsman
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- LICENSE.txt
|
37
|
+
- README.md
|
38
|
+
- bin/newsman
|
39
|
+
- lib/newsman.rb
|
40
|
+
- lib/newsman/pull_request.rb
|
41
|
+
- test/newsman/test_week_before.rb
|
42
|
+
homepage: https://github.com/volodya-lombrozo/newsman
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
- bin
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubygems_version: 3.5.6
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: GitHub user weekly news
|
66
|
+
test_files: []
|