accesslint-ci 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fa3733f759107ca29fd992d26ecd88efcc9684d8
4
+ data.tar.gz: 63f81acd0c0e944ce91de37eab291db58e4acd9e
5
+ SHA512:
6
+ metadata.gz: 2320999589fa6632918af2da7e898195120470dffca0f41f5c45ad6b1b3af2069e2744c93a682de7386c734411212e02d53ba5da0233a6191a736073030204e9
7
+ data.tar.gz: 4d79183eec4607ea405c7fc063bb14f2c4ad9b5f13e49ee0cea8dfb5798b7221fd521408cffc655ee54cdfb5d7be0405f93c9710e5967a006d83dd21ca971e1f
data/.env.sample ADDED
@@ -0,0 +1,5 @@
1
+ ACCESSLINT_GITHUB_TOKEN=
2
+ CIRCLE_BRANCH=
3
+ CIRCLE_PROJECT_REPONAME=
4
+ CIRCLE_PROJECT_USERNAME=
5
+ CIRCLE_TOKEN=
data/.env.test ADDED
@@ -0,0 +1,5 @@
1
+ CIRCLE_BRANCH=example-branch
2
+ CIRCLE_PROJECT_REPONAME=accesslint-ci.rb
3
+ CIRCLE_PROJECT_USERNAME=accesslint
4
+ CIRCLE_TOKEN=ABC123
5
+ ACCESSLINT_GITHUB_TOKEN=ABC456
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .env
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.3
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at cameron@thoughtbot.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in accesslint-ci.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Cameron Cundiff
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,54 @@
1
+ # Accesslint::Ci
2
+
3
+ Run accesslint-cli in CircleCI
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'accesslint-ci'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install accesslint-ci
20
+
21
+ ## Usage
22
+
23
+ general:
24
+ artifacts:
25
+ - "accesslint.log"
26
+
27
+ machine:
28
+ node:
29
+ version: 6.1.0
30
+
31
+ dependencies:
32
+ override:
33
+ - npm install -g accesslint-cli
34
+
35
+ test:
36
+ post:
37
+ - bundle exec puma -d -C./config/puma.rb
38
+ - accesslint-ci scan http://localhost:3000
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
43
+
44
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/accesslint-ci.rb/accesslint-ci. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
49
+
50
+
51
+ ## License
52
+
53
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
54
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'accesslint/ci/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "accesslint-ci"
8
+ spec.version = Accesslint::Ci::VERSION
9
+ spec.authors = ["Cameron Cundiff"]
10
+ spec.email = ["cameron@thoughtbot.com"]
11
+
12
+ spec.summary = %q{Run accesslint accessibility scanner in CI}
13
+ spec.description = %q{Run accesslint-cli accessibility assertions against a host url}
14
+ spec.homepage = "https://www.github.com/accesslint/accesslint-ci.rb"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "pry-byebug"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "dotenv"
27
+
28
+ spec.add_dependency "rest-client"
29
+ spec.add_dependency "thor"
30
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "accesslint/ci"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ brew install wget
9
+ npm install -g accesslint-cli
data/circle.yml ADDED
@@ -0,0 +1,8 @@
1
+ machine:
2
+ node:
3
+ version: 6.1.0
4
+
5
+ dependencies:
6
+ override:
7
+ - bundle install
8
+ - npm install -g accesslint-cli
@@ -0,0 +1,10 @@
1
+ require "accesslint/ci/version"
2
+ require "accesslint/ci/cli"
3
+ require "accesslint/ci/log_manager"
4
+ require "accesslint/ci/commenter"
5
+ require "accesslint/ci/scanner"
6
+
7
+ module Accesslint
8
+ module Ci
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ require "thor"
2
+
3
+ module Accesslint
4
+ module Ci
5
+ class Cli < Thor
6
+ desc "scan HOST", "scan HOST"
7
+ option :crawl, type: :boolean
8
+ def scan(host)
9
+ current = Scanner.perform(host: host, options: options).split("\n")
10
+
11
+ if ENV.fetch("CIRCLE_BRANCH") != "master"
12
+ existing = LogManager.get.split("\n")
13
+ diff = current - existing
14
+
15
+ if diff.any?
16
+ Commenter.perform(diff)
17
+ puts diff
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,81 @@
1
+ require "rest-client"
2
+
3
+ module Accesslint
4
+ module Ci
5
+ class Commenter
6
+ def self.perform(*args)
7
+ new(*args).perform
8
+ end
9
+
10
+ def initialize(diff)
11
+ @diff = diff
12
+ end
13
+
14
+ def perform
15
+ RestClient.post(github_uri, payload)
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :diff
21
+
22
+ def github_uri
23
+ @github_uri ||= "#{github_host}/issues/#{pull_request_number}/comments"
24
+ end
25
+
26
+ def github_host
27
+ URI.join(
28
+ "https://#{auth}@api.github.com/",
29
+ "repos/",
30
+ project_path,
31
+ )
32
+ end
33
+
34
+ def auth
35
+ "accesslint-ci:#{ENV.fetch('ACCESSLINT_GITHUB_TOKEN')}"
36
+ end
37
+
38
+ def pull_request_number
39
+ if ENV["CI_PULL_REQUEST"]
40
+ ENV.fetch("CI_PULL_REQUEST").match(/(\d+)/)[0]
41
+ else
42
+ pull_requests[0].fetch("number")
43
+ end
44
+ end
45
+
46
+ def pull_requests
47
+ @prs ||= JSON.parse(
48
+ RestClient.get(
49
+ "#{github_host}/pulls?head=#{pull_request_head}"
50
+ )
51
+ )
52
+ end
53
+
54
+ def pull_request_head
55
+ "#{ENV.fetch('CIRCLE_PROJECT_USERNAME')}:#{ENV.fetch('CIRCLE_BRANCH')}"
56
+ end
57
+
58
+ def payload
59
+ {
60
+ body: message,
61
+ }.to_json
62
+ end
63
+
64
+ def message
65
+ "Found #{diff.count} new accessibility issues: \n```\n#{snippet}\n```"
66
+ end
67
+
68
+ def snippet
69
+ diff.join("\n")
70
+ end
71
+
72
+ def project_path
73
+ [
74
+ ENV.fetch("CIRCLE_PROJECT_USERNAME"),
75
+ ENV.fetch("CIRCLE_PROJECT_REPONAME"),
76
+ ].join("/")
77
+ end
78
+ end
79
+ end
80
+ end
81
+
@@ -0,0 +1,66 @@
1
+ require "rest-client"
2
+ require "json"
3
+
4
+ module Accesslint
5
+ module Ci
6
+ class MissingArtifactError < StandardError; end
7
+ class LogManager
8
+ def self.get
9
+ new.get
10
+ end
11
+
12
+ def get
13
+ RestClient.get(
14
+ "#{artifact_url}?circle-token=#{ENV.fetch('CIRCLE_TOKEN')}"
15
+ )
16
+ rescue MissingArtifactError => e
17
+ puts e.message
18
+ "\n"
19
+ end
20
+
21
+ private
22
+
23
+ def artifact_url
24
+ @artifacts = JSON.parse(RestClient.get("#{artifacts_uri}?#{query}"))
25
+
26
+ artifact = @artifacts.first do |artifact|
27
+ artifact["path"].end_with?("accesslint.log")
28
+ end
29
+
30
+ if artifact
31
+ @artifact_url ||= artifact.fetch("url")
32
+ else
33
+ raise MissingArtifactError.new("No existing logs for comparison.")
34
+ end
35
+ end
36
+
37
+ def artifacts_uri
38
+ URI.join(
39
+ "https://circleci.com/",
40
+ "api/v1/project/",
41
+ project_path,
42
+ "latest/artifacts",
43
+ )
44
+ end
45
+
46
+ def project_path
47
+ [
48
+ ENV.fetch("CIRCLE_PROJECT_USERNAME"),
49
+ ENV.fetch("CIRCLE_PROJECT_REPONAME"),
50
+ ].join("/") + "/"
51
+ end
52
+
53
+ def query
54
+ URI.encode_www_form([
55
+ ["branch", branch],
56
+ ["filter", "successful"],
57
+ ["circle-token", ENV.fetch("CIRCLE_TOKEN")],
58
+ ])
59
+ end
60
+
61
+ def branch
62
+ "master"
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,59 @@
1
+ require "uri"
2
+ require "fileutils"
3
+
4
+ module Accesslint
5
+ module Ci
6
+ SITE_DIR = "tmp/accesslint-site".freeze
7
+ LOG_FILE = "tmp/accesslint.log".freeze
8
+
9
+ class Scanner
10
+ def self.perform(*args)
11
+ new(*args).perform
12
+ end
13
+
14
+ def initialize(host:, options: {})
15
+ @host = host
16
+ @options = options
17
+ end
18
+
19
+ def perform
20
+ create_site_dir
21
+ create_log_file
22
+ `#{crawl_site}`
23
+
24
+ File.read(LOG_FILE)
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :host, :options
30
+
31
+ def create_site_dir
32
+ if !File.exists?(SITE_DIR)
33
+ FileUtils::mkdir_p(SITE_DIR)
34
+ end
35
+ end
36
+
37
+ def create_log_file
38
+ if File.exists?(LOG_FILE)
39
+ FileUtils::rm(LOG_FILE)
40
+ end
41
+ end
42
+
43
+
44
+ def crawl_site
45
+ <<-SHELL
46
+ wget #{host} \
47
+ --convert-links \
48
+ --html-extension \
49
+ --mirror \
50
+ --directory-prefix #{SITE_DIR} \
51
+ --quiet
52
+
53
+ find #{SITE_DIR} -type f -name "*.html" | \
54
+ xargs -n 1 -P 5 accesslint >> #{LOG_FILE}
55
+ SHELL
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,5 @@
1
+ module Accesslint
2
+ module Ci
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: accesslint-ci
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Cameron Cundiff
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry-byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dotenv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rest-client
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: thor
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Run accesslint-cli accessibility assertions against a host url
112
+ email:
113
+ - cameron@thoughtbot.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".env.sample"
119
+ - ".env.test"
120
+ - ".gitignore"
121
+ - ".rspec"
122
+ - ".ruby-version"
123
+ - ".travis.yml"
124
+ - CODE_OF_CONDUCT.md
125
+ - Gemfile
126
+ - LICENSE.txt
127
+ - README.md
128
+ - Rakefile
129
+ - accesslint-ci.gemspec
130
+ - bin/console
131
+ - bin/setup
132
+ - circle.yml
133
+ - lib/accesslint/ci.rb
134
+ - lib/accesslint/ci/cli.rb
135
+ - lib/accesslint/ci/commenter.rb
136
+ - lib/accesslint/ci/log_manager.rb
137
+ - lib/accesslint/ci/scanner.rb
138
+ - lib/accesslint/ci/version.rb
139
+ homepage: https://www.github.com/accesslint/accesslint-ci.rb
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.5.1
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Run accesslint accessibility scanner in CI
163
+ test_files: []