Skip to content

Commit 0d85dad

Browse files
authored
Add some basic telemetry (#37)
* Telemetry * Use net/http * Switch to ruby 3.1 * Update changelog for v5.1.6
1 parent 7ecf1a1 commit 0d85dad

File tree

5 files changed

+37
-14
lines changed

5 files changed

+37
-14
lines changed

CHANGELOG.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
## master
22

3-
## v5 - updated on 20230110
3+
## v5.1.6 - updated on 20230304
4+
5+
- Send basic telemetry
6+
7+
## v5.1.5 - updated on 20230110
48

59
- Switch to using amazon linux 2 since the old blueprint became unavailable (#34)
610

7-
## v5 - updated on 20221108
11+
## v5.1.4 - updated on 20221108
812

913
- Fix pr_push event
1014

11-
## v5 - updated on 20221104
15+
## v5.1.3 - updated on 20221104
1216

1317
- Return :ignored action when no other action can be guessed.
1418
- Update system packages before running docker-compose.
1519
- Prune volumes before starting.
1620
- Add automated cleanup for dangling resources, to be launched as a scheduled job.
1721

18-
## v5 - updated on 20211201
22+
## v5.1.2 - updated on 20211201
1923

2024
- Fix issue with alpine ruby no longer having the correct ciphers for connecting to lightsail instances.
2125
- Properly handle `repository_dispatch` events.
2226
- Add support for private registries, e.g. `registries: docker://${{ secrets.GHCR_PAT }}@ghcr.io` in workflow file.
2327

24-
## v5 - 20210218
28+
## v5.1.1 - 20210218
2529

2630
- Add support for custom DNS.
2731
- Switch to human-readable subdomains that include the PR title inside.

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
FROM ruby:2.7-slim
1+
FROM ruby:3.1-slim
22

3-
RUN apt-get update -qq && apt-get install openssh-client git -y
3+
RUN apt-get -qq update && apt-get -qq -y install openssh-client git >/dev/null
44
WORKDIR /app
55
COPY Gemfile .
66
COPY Gemfile.lock .
7-
RUN bundle install -j 4
7+
RUN bundle install -j 4 --quiet
88
ADD . .
99

1010
ENTRYPOINT ["/app/bin/pullpreview"]

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ build:
44
shell:
55
docker run -e GITHUB_SHA=9cdcde5f00b76c97db398210dd5460b259176f9b -e GITHUB_TOKEN -e GITHUB_EVENT_PATH=/app/test/fixtures/github_event_push.json -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY --entrypoint /bin/sh -it --rm -v $(shell pwd):/app pullpreview/pullpreview
66

7-
87
bundle:
98
docker run --rm -v $(shell pwd):/app -w /app ruby:2-alpine bundle
109

lib/pull_preview/github_sync.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,13 @@ def sync!
8484
end
8585

8686
pp_action = guess_action_from_event.to_sym
87-
license = PullPreview::License.new(org_id, repo_id, pp_action).fetch!
87+
license = PullPreview::License.new(org_id, repo_id, pp_action, org_slug: org_name, repo_slug: repo_name).fetch!
8888
PullPreview.logger.info license.message
8989

90+
unless license.ok?
91+
raise LicenseError, license.message
92+
end
93+
9094
case pp_action
9195
when :pr_down, :branch_down
9296
instance = Instance.new(instance_name)

lib/pull_preview/license.rb

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,42 @@
11
require "json"
2+
require "net/http"
23

34
module PullPreview
45
class License
56
attr_reader :state, :message
67

7-
def initialize(org_id, repo_id, action)
8+
def initialize(org_id, repo_id, action, details = {})
89
@org_id = org_id
910
@repo_id = repo_id
1011
@action = action
12+
@details = details
1113
end
1214

1315
def ok?
1416
state == "ok"
1517
end
1618

1719
def params
18-
{org_id: @org_id, repo_id: @repo_id, pp_action: @action}
20+
@details.merge({org_id: @org_id, repo_id: @repo_id, pp_action: @action})
1921
end
2022

2123
def fetch!
22-
@state = "ok"
23-
@message = "License valid"
24+
uri = URI("https://app.pullpreview.com/licenses/check")
25+
uri.query = URI.encode_www_form(params)
26+
begin
27+
response = Net::HTTP.get_response(uri)
28+
if response.code == "200"
29+
@state = "ok"
30+
@message = response.body
31+
else
32+
@state = "ko"
33+
@message = response.body
34+
end
35+
rescue Exception => e
36+
PullPreview.logger.warn "License server unreachable - #{e.message}"
37+
@state = "ok"
38+
@message = "License server unreachable. Continuing..."
39+
end
2440
self
2541
end
2642
end

0 commit comments

Comments
 (0)