Skip to content

Commit

Permalink
Merge pull request alphagov#70 from alphagov/topics
Browse files Browse the repository at this point in the history
Only show PRs for repositories with the govuk topic
  • Loading branch information
thomasleese authored Sep 24, 2018
2 parents b14e2fa + 9617645 commit 149b7bf
Show file tree
Hide file tree
Showing 15 changed files with 602 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.2
2.5.1
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ group :development, :test do
end

group :test do
gem 'climate_control', '~> 0.2'
gem 'pry', '~> 0.11.3'
gem 'rack-test', '~> 0.8.0'
gem 'rspec', '~> 3.7.0'
gem 'timecop', '~> 0.9.1'
gem 'webmock', '~> 3.3.0'
gem 'vcr', '~> 4.0'
end
75 changes: 40 additions & 35 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,44 @@ GEM
specs:
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
ast (2.3.0)
ast (2.4.0)
climate_control (0.2.0)
coderay (1.1.2)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.3)
faraday (0.14.0)
faraday (0.15.3)
multipart-post (>= 1.2, < 3)
ffi (1.9.18)
govuk-lint (3.6.0)
rubocop (~> 0.51.0)
rubocop-rspec (~> 1.19.0)
ffi (1.9.25)
govuk-lint (3.9.0)
rubocop (~> 0.58)
rubocop-rspec (~> 1.28)
scss_lint
hashdiff (0.3.7)
kgio (2.11.1)
jaro_winkler (1.5.1)
kgio (2.11.2)
method_source (0.9.0)
multipart-post (2.0.0)
mustermann (1.0.1)
octokit (4.8.0)
mustermann (1.0.3)
octokit (4.12.0)
sawyer (~> 0.8.0, >= 0.5.3)
parallel (1.12.1)
parser (2.4.0.2)
ast (~> 2.3)
powerpack (0.1.1)
parser (2.5.1.2)
ast (~> 2.4.0)
powerpack (0.1.2)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
public_suffix (3.0.1)
rack (2.0.3)
rack-protection (2.0.0)
public_suffix (3.0.3)
rack (2.0.5)
rack-protection (2.0.4)
rack
rack-test (0.8.2)
rack-test (0.8.3)
rack (>= 1.0, < 3)
rainbow (2.2.2)
rake
rainbow (3.0.0)
raindrops (0.19.0)
rake (12.3.0)
rb-fsevent (0.10.2)
rake (12.3.1)
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
rspec (3.7.0)
Expand All @@ -63,43 +64,45 @@ GEM
rspec-mocks (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.0)
rubocop (0.51.0)
rspec-support (3.7.1)
rubocop (0.59.1)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0)
parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 3.0)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
rubocop-rspec (1.19.0)
rubocop (>= 0.51.0)
ruby-progressbar (1.9.0)
rubocop-rspec (1.29.1)
rubocop (>= 0.58.0)
ruby-progressbar (1.10.0)
safe_yaml (1.0.4)
sass (3.5.5)
sass (3.5.7)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
sawyer (0.8.1)
addressable (>= 2.3.5, < 2.6)
faraday (~> 0.8, < 1.0)
scss_lint (0.56.0)
scss_lint (0.57.0)
rake (>= 0.9, < 13)
sass (~> 3.5.3)
sinatra (2.0.0)
sass (~> 3.5.5)
sinatra (2.0.4)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.0)
rack-protection (= 2.0.4)
tilt (~> 2.0)
slack-poster (2.2.1)
faraday (~> 0.9)
thor (0.20.0)
tilt (2.0.8)
timecop (0.9.1)
unicode-display_width (1.3.0)
unicorn (5.4.0)
unicode-display_width (1.4.0)
unicorn (5.4.1)
kgio (~> 2.6)
raindrops (~> 0.7)
vcr (4.0.0)
webmock (3.3.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
Expand All @@ -110,6 +113,7 @@ PLATFORMS

DEPENDENCIES
bundler-audit!
climate_control (~> 0.2)
govuk-lint
octokit (~> 4.3)
pry (~> 0.11.3)
Expand All @@ -120,10 +124,11 @@ DEPENDENCIES
slack-poster (~> 2.2)
timecop (~> 0.9.1)
unicorn
vcr (~> 4.0)
webmock (~> 3.3.0)

RUBY VERSION
ruby 2.4.2p198
ruby 2.5.1p57

BUNDLED WITH
1.16.1
10 changes: 10 additions & 0 deletions lib/domain/repository.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Domain
class Repository
attr_reader :name, :url

def initialize(name:, url:)
@name = name
@url = url
end
end
end
24 changes: 15 additions & 9 deletions lib/gateways/pull_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,21 @@ def changes_requested_pull_requests
end

def build_pull_requests(api_response, status)
api_response.map do |pr|
Domain::PullRequest.new(
application_name: get_application_name(pr),
title: pr.title,
url: pr.html_url,
status: status,
opened_at: Date.parse(pr.created_at.to_s)
)
end
api_response
.select { |pr| govuk_repository_urls.include?(pr.repository_url) }
.map do |pr|
Domain::PullRequest.new(
application_name: get_application_name(pr),
title: pr.title,
url: pr.html_url,
status: status,
opened_at: Date.parse(pr.created_at.to_s),
)
end
end

def govuk_repository_urls
@govuk_repository_urls ||= Gateways::Repositories.new.execute.map(&:url)
end

def get_application_name(pull_request)
Expand Down
18 changes: 18 additions & 0 deletions lib/gateways/repositories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require "octokit"

module Gateways
class Repositories
def initialize
@octokit = Octokit::Client.new(
access_token: ENV.fetch("GITHUB_TOKEN"),
auto_paginate: true,
)
end

def execute
@octokit.search_repos("topic:govuk").items.map do |repo|
Domain::Repository.new(name: repo.name, url: repo.url)
end
end
end
end
10 changes: 9 additions & 1 deletion spec/acceptance/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
include Rack::Test::Methods
def app() described_class end

around do |example|
ClimateControl.modify GITHUB_TOKEN: "some_token" do
VCR.use_cassette("repositories") do
example.run
end
end
end

context 'Dashboard' do
context 'given open pull requests' do
before do
Expand Down Expand Up @@ -238,7 +246,7 @@ def app() described_class end
it 'should display the total PRs opened by dependabot' do
get '/stats'
expect(last_response).to be_ok
expect(last_response.body).to include('Total PRs opened by Dependabot: 3')
expect(last_response.body).to include('Total PRs opened by Dependabot: 4')
end
end

Expand Down
8 changes: 8 additions & 0 deletions spec/acceptance/dependapanda_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
require_relative '../../dependapanda'

describe Dependapanda do
around do |example|
ClimateControl.modify GITHUB_TOKEN: "some_token" do
VCR.use_cassette("repositories") do
example.run
end
end
end

before do
ENV['SLACK_WEBHOOK_URL'] = 'http://example.com/webhook'

Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/gemfile_with_no_security_alerts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ GEM
railties (>= 3.0.0)
faraday (0.12.2)
multipart-post (>= 1.2, < 3)
ffi (1.9.18)
ffi (1.9.24)
gds-api-adapters (50.7.0)
link_header
lrucache (~> 0.1.1)
Expand Down
62 changes: 60 additions & 2 deletions spec/fixtures/pull_requests.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"total_count": 3,
"total_count": 4,
"incomplete_results": false,
"items": [
{
Expand Down Expand Up @@ -178,7 +178,65 @@
},
"body": "Bumps [gds-api-adapters](https://github.com/alphagov/gds-api-adapters) from 13.0.0 to 13.5.1.\n- [Changelog](https://github.com/alphagov/gds-api-adapters/blob/master/CHANGELOG.md)\n- [Commits](https://github.com/alphagov/gds-api-adapters/compare/v13.0.0...v13.5.1)\n\n[![Dependabot compatibility score](https://api.dependabot.com/badges/ci_status?dependency-name=gds-api-adapters&package-manager=bundler&previous-version=13.0.0&new-version=13.5.1)](https://dependabot.com/compatibility-score.html?dependency-name=gds-api-adapters&package-manager=bundler&previous-version=13.0.0&new-version=13.5.1)\n\nDependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.\n\nIf you'd like to skip this version, you can just close this PR. If you have any feedback just mention @dependabot in the comments below.",
"score": 1.0
},
{
"url": "https://api.github.com/repos/alphagov/govwifi-logging-api/issues/761",
"repository_url": "https://api.github.com/repos/alphagov/govwifi-logging-api",
"labels_url": "https://api.github.com/repos/alphagov/govwifi-logging-api/issues/761/labels{/name}",
"comments_url": "https://api.github.com/repos/alphagov/govwifi-logging-api/issues/761/comments",
"events_url": "https://api.github.com/repos/alphagov/govwifi-logging-api/issues/761/events",
"html_url": "https://github.com/alphagov/govwifi-logging-api/pull/761",
"id": 291411556,
"number": 761,
"title": "Bump gds-sso from 13.5.0 to 13.5.1",
"user": {
"login": "dependabot[bot]",
"id": 27856297,
"avatar_url": "https://avatars3.githubusercontent.com/in/2141?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/dependabot%5Bbot%5D",
"html_url": "https://github.com/apps/dependabot",
"followers_url": "https://api.github.com/users/dependabot%5Bbot%5D/followers",
"following_url": "https://api.github.com/users/dependabot%5Bbot%5D/following{/other_user}",
"gists_url": "https://api.github.com/users/dependabot%5Bbot%5D/gists{/gist_id}",
"starred_url": "https://api.github.com/users/dependabot%5Bbot%5D/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/dependabot%5Bbot%5D/subscriptions",
"organizations_url": "https://api.github.com/users/dependabot%5Bbot%5D/orgs",
"repos_url": "https://api.github.com/users/dependabot%5Bbot%5D/repos",
"events_url": "https://api.github.com/users/dependabot%5Bbot%5D/events{/privacy}",
"received_events_url": "https://api.github.com/users/dependabot%5Bbot%5D/received_events",
"type": "Bot",
"site_admin": false
},
"labels": [
{
"id": 779829793,
"url": "https://api.github.com/repos/alphagov/govwifi-logging-api/labels/dependencies",
"name": "dependencies",
"color": "0025ff",
"default": false
}
],
"state": "closed",
"locked": false,
"assignee": null,
"assignees": [

],
"milestone": null,
"comments": 0,
"created_at": "2018-01-24T07:41:46Z",
"updated_at": "2018-01-24T08:08:41Z",
"closed_at": "2018-01-24T08:08:27Z",
"author_association": "NONE",
"pull_request": {
"url": "https://api.github.com/repos/alphagov/govwifi-logging-api/pulls/761",
"html_url": "https://github.com/alphagov/govwifi-logging-api/pull/761",
"diff_url": "https://github.com/alphagov/govwifi-logging-api/pull/761.diff",
"patch_url": "https://github.com/alphagov/govwifi-logging-api/pull/761.patch"
},
"body": "Bumps [gds-sso](https://github.com/alphagov/gds-sso) from 13.5.0 to 13.5.1.\n- [Changelog](https://github.com/alphagov/gds-sso/blob/master/CHANGELOG.md)\n- [Commits](https://github.com/alphagov/gds-sso/compare/v13.5.0...v13.5.1)\n\n[![Dependabot compatibility score](https://api.dependabot.com/badges/ci_status?dependency-name=gds-sso&package-manager=bundler&previous-version=13.5.0&new-version=13.5.1)](https://dependabot.com/compatibility-score.html?dependency-name=gds-sso&package-manager=bundler&previous-version=13.5.0&new-version=13.5.1)\n\nDependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.\n\nIf you'd like to skip this version, you can just close this PR. If you have any feedback just mention @dependabot in the comments below.",
"score": 1.0
}
]
}

Loading

0 comments on commit 149b7bf

Please sign in to comment.