• Stars
    star
    826
  • Rank 55,195 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

✅ Validate links in awesome projects

awesome_bot

Verify links in awesome projects

Gem Version Test

awesome_bot checks for valid URLs in a file, it can be used to verify pull requests updating a README.

Installation

$ gem install awesome_bot

Usage

Command Line

Usage: awesome_bot [file or files]
       awesome_bot [options]
    -f, --files [files]              Comma separated files to check
    -a, --allow [errors]             Status code errors to allow
        --allow-dupe                 Duplicate URLs are allowed
        --allow-ssl                  SSL errors are allowed
        --allow-redirect             Redirected URLs are allowed
        --allow-timeout              URLs that time out are allowed
        --base-url [base url]        Base URL to use for relative links
    -d, --request-delay [seconds]    Set request delay
    -t, --set-timeout [seconds]      Set connection timeout (default: 30)
        --skip-save-results          Skip saving results
    -w, --white-list [urls]          Comma separated URLs to white list
  • You can check multiple files (comma separated or * pattern, look below for details).

  • By default, duplicate URLs or any status code other than 200 are flagged as failures.

    • Use option --allow-dupe to allow duplicates.
    • Use option --allow-redirect to allow redirects.
    • Use option --allow to allow specific status code errors.
    • Use option --white-list (-w for short) to prevent links from being flagged: -w domain1.com/post/article,domain2.com white lists domain1.com/post/article and all links matching domain2.com.

Examples

$ awesome_bot README.md
> Checking links in README.md
Links found: 56, 37 unique
  01. https://github.com/sindresorhus/awesome
  02. http://i.giphy.com/urvsFBDfR6N32.gif
  03. https://travis-ci.org/dkhamsing/awesome_bot.svg
# ...
  37. https://github.com/dkhamsing
  Checking URLs: ✓✓✓→?✓→✓→→✓✓→✓✓✓→✓✓✓✓✓✓✓✓✓✓✓→✓✓✓✓✓→✓✓

Issues :-(
> Links
  1. [L007] 301 https://travis-ci.org/dkhamsing/awesome_bot.svg → https://api.travis-ci.org/dkhamsing/awesome_bot.svg
  2. [L008] 302 https://badge.fury.io/rb/awesome_bot → http://rubygems.org/gems/awesome_bot
# ...
> Dupes
  1. [L03] https://github.com/sindresorhus/awesome
  2. [L05] http://i.giphy.com/urvsFBDfR6N32.gif
# ...
$ awesome_bot README.md --allow-dupe --allow-redirect -w rubydoc,giphy
# allow redirects, dupes and white list all links matching rubydoc and giphy

$ awesome_bot README.md,README-zh.md
# check links in 2 files

$ awesome_bot docs/*.md
# check all Markdown files in the docs/ directory

$ awesome_bot README.md --allow-timeout -t 5
# speed up validation by setting a timeout of 5 seconds per link request and allowing timeouts

$ awesome_bot README.md --allow 403,429
# allow status code errors 403 and 429
# --allow 301 would be similar to --allow-redirect

$ awesome_bot README.md --base-url https://github.com/IDR/idr-notebooks/blob/master/
# check relative links using the base URL provided
(master) $ git branch
* master
(master) $ git checkout -b new-branch
Switched to a new branch 'new-branch'
(new-branch) $ touch new-readme.md && echo 'https://github.com/dkhamsing' >> new-readme.md
(new-branch) $ git add new-readme.md
(new-branch) $ git commit -m 'Testing'
[new-branch ef47336] Testing
 1 file changed, 1 insertion(+)
 create mode 100644 new-readme.md
(new-branch) $ git diff master.. --name-only | grep '.md' | xargs awesome_bot
> Checking links in new-readme.md
Links to check: 1
  1. https://github.com/dkhamsing
Checking URLs: ✓
No issues :-)

Wrote results to ab-results-new-readme.md.json

Docker Examples

If you do not want to install Ruby or its dependencies you can simply use Docker and Docker image.

Here is an example for checking the links in the Markdown files in your current directory/subdirectories:

docker run -ti --rm -v $PWD:/mnt:ro dkhamsing/awesome_bot --white-list "test.com" --allow-dupe --allow-redirect --skip-save-results `find . -name "*.md"`

or just check the links in a single file located at ./templates/ubuntu.md:

docker run -ti --rm -v $PWD:/mnt:ro dkhamsing/awesome_bot --allow-dupe --allow-redirect --skip-save-results ./templates/ubuntu.md

You always need to specify the path to the file so you cannot simply use *.md; instead use ls *.md":

docker run -ti --rm -v $PWD:/mnt:ro dkhamsing/awesome_bot --white-list "test.com" --allow-dupe --allow-redirect --skip-save-results `ls *.md`

Library

irb(main):001:0> require 'awesome_bot'
=> true
irb(main):002:0> content = File.read 'README.md'
=> "..."
irb(main):003:0> result = AwesomeBot.check content
=> #<AwesomeBot::Result:0x007fdde39f4408 @links=...>
# AwesomeBot Result with success, statuses_issues, dupes and more
irb(main):004:0> puts result.success ? 'No errors' : ':-('
:-(

More information at rubydoc.

Validate Pull Requests

Does your GitHub README contain a lot of links? awesome_bot can help you validate them when a pull request is created (or a commit is pushed). It is used by:

and more.

Tips

  • Use the keyword [ci skip] in your commit title/message to skip verification.
  • Use Danger.

GitHub Actions

To use awesome_bot with GitHub Actions (workflows), here is an example:

name: Ruby

on:
  push:
    branches: [ '*' ]
  pull_request:
    branches: [ '*' ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: Set up Ruby 2.6
      uses: ruby/setup-ruby@v1
      with:
        ruby-version: '2.6'
    - name: Checks
      run: |
        gem install awesome_bot
        awesome_bot check-unique.txt --allow-ssl -a 302,429 -w xbmc/xbmc

Travis CI

To use awesome_bot with Travis CI, connect your repo and create a .travis.yml file.

language: ruby
rvm: 2.4.1
before_script: gem install awesome_bot
script: awesome_bot README.md

To turn off email notifications, add the lines below

notifications:
  email: false

In case you want to use the docker image inside Travis CI follow this example which will check broken links in all *.md files in your repository:

sudo: required

services:
  - docker

script:
  # Link Checks
  - docker run -ti --rm -v $PWD:/mnt:ro dkhamsing/awesome_bot --allow-dupe --allow-redirect --skip-save-results `find . -name "*.md"`

More

CircleCI, Codeship, and Semaphore CI support running tests without adding a file to the repo (a public configuration file can however help others contribute).

# Codeship
Setup
rvm use 2.4.1 --install
gem install awesome_bot

Test
awesome_bot README.md
# Semaphore CI
Language: Ruby
Ruby version: 2.4.1
Databases for: don't generate
Setup:
gem install awesome_bot
awesome_bot README.md

Status Badge

Build Status

To add the Travis CI build status badge above to your project, use the following code

[![Build Status](https://travis-ci.org/<username>/<project>.svg)](https://travis-ci.org/<username>/<project>)

i.e.
[![Build Status](https://travis-ci.org/dkhamsing/awesome_bot.svg?branch=master)](https://travis-ci.org/dkhamsing/awesome_bot)

As it happens, the default code snippet provided contains a redirect so adding a badge could fail your status 😭.. one way to fix this is to white list travis-ci, i.e.

- awesome_bot README.md --white-list travis-ci

You can also add a badge for other CI tools, check out shields.io.

Danger

Integrate awesome_bot with Danger and have results reported back to the pull request.

danger

Here's the step in your Dangerfile:

# Check links
require 'json'
results = File.read 'ab-results-README.md-markdown-table.json'
j = JSON.parse results
if j['error']==true
  fail j['title']
  markdown j['message']
end

Contact

License

This project is available under the MIT license. See the LICENSE file for more info.

More Repositories

1

open-source-ios-apps

📱 Collaborative List of Open-Source iOS Apps
41,887
star
2

ios-asset-names

📐 Guide to name iOS assets
Swift
670
star
3

frankenstein

:octocat: Correct README Redirects
Ruby
308
star
4

ScrollTab

Scrolling Tab for iOS
Objective-C
267
star
5

dkhamsing.github.io

:octocat: My GitHub Page
Ruby
221
star
6

news

📰 iOS news app in the style of Apple News, CNN, BBC, Facebook, NYT, Twitter, Reddit & more
Swift
217
star
7

TabDump

📰 TabDump app for iOS
Objective-C
98
star
8

osia

:octocat: iOS app to browse open-source-ios-apps
Swift
88
star
9

apns-guide

🔔 Guide to setup APNS
86
star
10

DKImageBrowser

iOS Image Browser with a Thumbnail Strip
Objective-C
56
star
11

stocks

📈 Basic iOS app to track stocks (data from Finnhub, Tiingo, or IEX Cloud)
Swift
42
star
12

covid19.swift

🌐 Small iOS app to show some COVID-19 health, data, news and tweets
Swift
27
star
13

listapp.ios

✨ Basic lists from iOS 2 to iOS 15
Swift
27
star
14

fastmdb

🔍 Fast iOS app to browse and search movies, tv, actors, credits
Swift
22
star
15

how-much

💰 iOS price list app using Firebase, Realm & more
Objective-C
21
star
16

xcode-readme

🔍 Correct the spelling of Xcode in a README
Ruby
10
star
17

GitHubOAuthController

:octocat: Simple GitHub OAuth Controller for iOS
Objective-C
10
star
18

cocoapods-readme

🔍 Correct the spelling of CocoaPods in a README
Ruby
9
star
19

pdf_xcassets

🚋 Generate Xcode xcassets for PDF assets
Ruby
8
star
20

upcomingtv

📆 iOS app to track when your favorite tv show airs next
Swift
8
star
21

github-readme

:octocat: Get the README from a GitHub repo
Ruby
6
star
22

update_profile_pic

👤 Update your Twitter profile pic in a snap
Ruby
6
star
23

delete_my_tweets

🐤 Delete my tweets
Ruby
5
star
24

markdown_html

📄 The simplest way to convert Markdown to HTML
Ruby
4
star
25

readme-correct

😁 Fix GitHub typos with ease
Ruby
4
star
26

tumblr_uploadr

🐼 Tumblr photo batch uploader
Ruby
3
star
27

forker

🍴 Fork GitHub repos found on a page
Ruby
2
star
28

covid19cli

⚡ Quick CLI for COVID-19 data
Ruby
2
star
29

twitter_oauth_token

✋ Twitter OAuth token Ruby library
Ruby
1
star