Commit d9765899 authored by Marco Metz's avatar Marco Metz
Browse files

Initial rewrite

parent e187fcf5
source 'https://rubygems.org'
# Specify your gem's dependencies in cronjob_service.gemspec
# Specify your gem's dependencies in codeclimate_reporter.gemspec
gemspec
PATH
remote: .
specs:
cronjob_service (1.0.0)
codeclimate_reporter (1.0.0)
capybara
selenium-webdriver
GEM
remote: https://rubygems.org/
specs:
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
capybara (3.12.0)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (~> 1.2)
xpath (~> 3.2)
childprocess (0.9.0)
ffi (~> 1.0, >= 1.0.11)
ffi (1.9.25)
mini_mime (1.0.1)
mini_portile2 (2.3.0)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
public_suffix (3.0.3)
rack (2.0.6)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rake (10.5.0)
regexp_parser (1.3.0)
rubyzip (1.2.2)
selenium-webdriver (3.141.0)
childprocess (~> 0.5)
rubyzip (~> 1.2, >= 1.2.2)
xpath (3.2.0)
nokogiri (~> 1.8)
PLATFORMS
ruby
DEPENDENCIES
bundler (~> 1.7)
cronjob_service!
codeclimate_reporter!
rake (~> 10.0)
BUNDLED WITH
1.14.6
1.17.1
# CronjobService
# CodeclimateReporter
Pushes a notification to the Dashboard app to notify that a cronjob occured.
......@@ -8,7 +8,7 @@ Pushes a notification to the Dashboard app to notify that a cronjob occured.
Add this line to your application's Gemfile:
```ruby
gem "cronjob_service", git: "ssh://git@git.ikusei.de:7999/ik/cronjobnotificationtodashboard.git"
gem "codeclimate_reporter", git: "https://@git.ikusei.de/scm/ik/codeclimate-reporter.git"
```
And then execute:
......@@ -20,11 +20,11 @@ $ bundle
## Usage
```ruby
CronjobService::Notifier.push("project_id", "cronjob_title")
CodeclimateReporter::Notifier.push("project_id", "cronjob_title")
```
```ruby
CronjobService::Notifier.push("project_id", "cronjob_title", description: "My Description", foo: "bar")
CodeclimateReporter::Notifier.push("project_id", "cronjob_title", description: "My Description", foo: "bar")
```
......
require "bundler/gem_tasks"
task :console do
exec "irb -r cronjob_service -I ./lib"
exec "irb -r codeclimate_reporter -I ./lib"
end
......@@ -3,11 +3,11 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'cronjob_service/version'
require 'codeclimate_reporter/version'
Gem::Specification.new do |spec|
spec.name = "cronjob_service"
spec.version = CronjobService::VERSION
spec.name = "codeclimate_reporter"
spec.version = CodeclimateReporter::VERSION
spec.authors = ["Marco Metz"]
spec.email = ["marco.metz@gmail.com"]
spec.summary = %q{Push a Notification to dashboard app}
......@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
spec.add_dependency "capybara"
spec.add_dependency "selenium-webdriver"
spec.add_development_dependency "bundler", "~> 1.7"
spec.add_development_dependency "rake", "~> 10.0"
end
# encoding: utf-8
require "capybara"
require "capybara/dsl"
require "open-uri"
require "json"
require "openssl"
require "codeclimate_reporter/version"
require "codeclimate_reporter/api_request_service"
module CodeclimateReporter
class Branch
include Capybara::DSL
def refresh
token = "d0f4c1fceb77106b9c4487833d8136d799d76046"
uri = "https://api.codeclimate.com/v1/orgs/56d6a63c55f3f16f1e004b94/repos"
headers = {"Authorization": "Token token=#{token}", "Accept": "application/vnd.api+json"}
api = CodeclimateReporter::ApiRequestService.new(uri, {}, headers )
result = JSON.parse(api.get_request.body)
current_project = result["data"].select{|a| a["attributes"]["human_name"] == "Quirin Privatbank"}.first
repo_url = current_project["links"]["self"]
branch_url = [repo_url, "branches"].join("/")
Capybara.current_driver = :selenium_chrome_headless
page.visit("https://codeclimate.com/login")
page.within(:xpath, ".//form[@id='new_login_form']") do
page.fill_in 'Email', with: 'm.metz@ikusei.de'
page.fill_in 'Password', with: '257-nQA-T6U-9rW'
end
page.click_button "Log in"
p branch_url
page.visit(branch_url)
page.click_link "Refresh"
sleep 15
current_branch = `git rev-parse --abbrev-ref HEAD`.chomp
p repo_url + "/compare/" + current_branch
page.click_link current_branch
page.click_link "Analyze"
p "Please check back in a few minutes."
end
end
end
# frozen_string_literal: true
# Base class for POST and GET requests
#
# @author Marco Metz, Holger Frohloff
# @uri [String] The Uri that is targeted with the request
# @params [Hash] An optional hash of parameters for the request
# @headers [Hash] An optional hash of headers for the request
#
require "addressable/uri"
require "net/http"
module CodeclimateReporter
class ApiRequestService
def initialize(uri, params = {}, headers = {})
@uri = uri
@params = params
@headers = headers
@request = nil
end
def get_request
uri = Addressable::URI.parse(@uri.strip).normalize
uri.query = [uri.query, URI.encode_www_form(@params)].join("&") if @params && @params.any?
@request = Net::HTTP::Get.new(uri.request_uri)
@headers.each do |key, value|
@request.add_field key, value
end
http = Net::HTTP.new(uri.hostname, uri.port)
if @uri.to_s.include?("https://")
http = Net::HTTP.new(uri.hostname, 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
http.request(@request)
rescue Timeout::Error
raise ApiTimeoutError
end
def to_s
{
request: request,
body: request.body.to_s,
headers: headers,
login: login,
params: params,
uri: uri
}.to_s
end
end
# A custom error class.
#
# API requests might time out. Whenever a timeout error occurs, a custom ApiTimeoutError is raised.
# Currently this has no specific effect.
#
# @author Holger Frohloff
class ApiTimeoutError < StandardError
end
end
# encoding: utf-8
module CronjobService
module CodeclimateReporter
VERSION = "1.0.0"
end
# encoding: utf-8
require 'open-uri'
require "cronjob_service/version"
module CronjobService
class Notifier
def self.push(project_id, cron_identifier, options = {})
raise "project_id missing" if project_id.nil?
raise "cron_identifier missing" if cron_identifier.nil?
base_url = "https://dashboard.dev-ikusei.de/api/v1/cronjob"
parameterized_options = options.map { |key, value| "&#{key}=#{value}"}.join
post_url = ["#{base_url}/#{project_id}?title=#{cron_identifier}", parameterized_options].join("&")
begin
open(post_url).read
rescue
puts "https://dashboard.dev-ikusei.de ist nicht erreichbar"
end
end
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment