clearlinux/ok.sh

Name: ok.sh

Owner: Clear Linux* Project for Intel Architecture

Description: A Bourne shell GitHub API client library focused on interfacing with shell scripts

Created: 2015-10-05 14:49:35.0

Updated: 2016-07-26 17:05:05.0

Pushed: 2015-10-05 15:26:44.0

Homepage:

Size: 230

Language: Shell

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Build Status

A GitHub API client library written in POSIX sh

Requirements
Optional requirements
Setup

Authentication credentials are read from a ~/.netrc file. Generate the token on GitHub under “Account Settings -> Applications”. Restrict permissions on that file with chmod 600 ~/.netrc!

machine api.github.com
    login <username>
    password <token>
Configuration

The following environment variables may be set to customize ok.sh.

_main()
Usage

Usage: ok.sh [<flags>] (command [<arg>, <name=value>...])

  ok.sh -h              # Short, usage help text.
  ok.sh help            # All help text. Warning: long!
  ok.sh help command    # Command-specific help text.
  ok.sh command         # Run a command with and without args.
  ok.sh command foo bar baz=Baz qux='Qux arg here'

See the full list of commands below.

Flags must be the first argument to ok.sh, before command.

Flag | Description —- | ———– -V | Show version. -h | Show this screen. -j | Output raw JSON; don't process with jq. -q | Quiet; don't print to stdout. -r | Print current GitHub API rate limit to stderr. -v | Logging output; specify multiple times: info, debug, trace. -x | Enable xtrace debug logging. -y | Answer 'yes' to any prompts.

Utility and request/response commands

all_funcs, main, log, helptext, format_json, format_urlencode, filter_json, get_mime_type, get_confirm, opts_filter, opts_pagination, opts_qs, request, response, get, post, _delete

GitHub commands

help, show_scopes, org_repos, org_teams, list_repos, create_repo, delete_repo, list_releases, release, create_release, delete_release, release_assets, upload_asset, list_milestones, list_issues, user_issues, org_issues

Table of Contents
help()

Output the help text for a command

Usage:

help commandname

Positional arguments

_all_funcs()

List all functions found in the current file in the order they appear

Keyword arguments

_log()

A lightweight logging system based on file descriptors

Usage:

_log debug 'Starting the combobulator!'

Positional arguments

_helptext()

Extract contiguous lines of comments and function params as help text

Indentation will be ignored. She-bangs will be ignored. The _main() function will be ignored. Local variable declarations and their default values can also be pulled in as documentation. Exits upon encountering the first blank line.

Exported environment variables can be used for string interpolation in the extracted commented text.

Input

Positional arguments

_format_json()

Create formatted JSON from name=value pairs

Usage:

mat_json foo=Foo bar=123 baz=true qux=Qux=Qux quux='Multi-line
ng'

Return:

r":123,"qux":"Qux=Qux","foo":"Foo","quux":"Multi-line\nstring","baz":true}

Tries not to quote numbers and booleans. If jq is installed it will also validate the output.

Positional arguments

_format_urlencode()

URL encode and join name=value pairs

Usage:

mat_urlencode foo='Foo Foo' bar='<Bar>&/Bar/'

Return:

Foo%20Foo&bar=%3CBar%3E%26%2FBar%2F

Ignores pairs if the value begins with an underscore.

_filter_json()

Filter JSON input using jq; outputs raw JSON if jq is not installed

Usage:

_filter_json '.[] | "\(.foo)"' < something.json
_get_mime_type()

Guess the mime type for a file based on the file extension

Usage:

local mime_type
_get_mime_type "foo.tar"; printf 'mime is: %s' "$mime_type"

Sets the global variable mime_type with the result. (If this function is called from within a function that has declared a local variable of that name it will update the local copy and not set a global.)

Positional arguments

_get_confirm()

Prompt the user for confirmation

Usage:

local confirm; _get_confirm
[ "$confirm" -eq 1 ] && printf 'Good to go!\n'

If global confirmation is set via $OK_SH_DESTRUCTIVE then the user is not prompted. Assigns the user's confirmation to the confirm global variable. (If this function is called within a function that has a local variable of that name, the local variable will be updated instead.)

Positional arguments

_opts_filter()

Extract common jq filter keyword options and assign to vars

Usage:

  local filter
  _opts_filter "$@"
_opts_pagination()

Extract common pagination keyword options and assign to vars

Usage:

  local _follow_next
  _opts_pagination "$@"
_opts_qs()

Format a querystring to append to an URL or a blank string

Usage:

  local qs
  _opts_qs "$@"
  _get "/some/path"
_request()

A wrapper around making HTTP requests with curl

Usage:

uest /repos/:owner/:repo/issues
tf '{"title": "%s", "body": "%s"}\n' "Stuff" "Things" \
_request /repos/:owner/:repo/issues | jq -r '.[url]'
tf '{"title": "%s", "body": "%s"}\n' "Stuff" "Things" \
_request /repos/:owner/:repo/issues method=PUT | jq -r '.[url]'

Input

Positional arguments

Keyword arguments

_response()

Process an HTTP response from curl

Output only headers of interest followed by the response body. Additional processing is performed on select headers to make them easier to work with in sh. See below.

Usage:

uest /some/path | _response status_code ETag Link_next
 -isS example.com/some/path | _response status_code status_text | {
cal status_code status_text
ad -r status_code
ad -r status_text

Header reformatting

Positional arguments

_get_mime_type()

Guess the mime type for a file based on the file extension

Usage:

local mime_type
_get_mime_type "foo.tar"; printf 'mime is: %s' "$mime_type"

Sets the global variable mime_type with the result. (If this function is called from within a function that has declared a local variable of that name it will update the local copy and not set a global.)

Positional arguments

_post()

A wrapper around _request() for commoon POST / PUT patterns

Usage:

_format_json foo=Foo bar=Bar | _post /some/path
_format_json foo=Foo bar=Bar | _post /some/path method='PUT'
_post /some/path filename=somearchive.tar
_post /some/path filename=somearchive.tar mime_type=application/x-tar
_post /some/path filename=somearchive.tar \
  mime_type=$(file -b --mime-type somearchive.tar)

Input

Positional arguments

Keyword arguments

_delete()

A wrapper around _request() for common DELETE patterns

Usage:

_delete '/some/url'

Return: 0 for success; 1 for failure.

Positional arguments

show_scopes()

Show the permission scopes for the currently authenticated user

Usage:

show_scopes
org_repos()

List organization repositories

Usage:

org_repos myorg
org_repos myorg type=private per_page=10
org_repos myorg _filter='.[] | "\(.name)\t\(.owner.login)"'

Positional arguments

Keyword arguments

Querystring arguments may also be passed as keyword arguments: per_page, type

org_teams()

List teams

Usage:

org_teams org

Positional arguments

Keyword arguments

list_repos()

List user repositories

Usage:

list_repos
list_repos user

Positional arguments

Keyword arguments

Querystring arguments may also be passed as keyword arguments: per_page, type, sort, direction

create_repo()

Create a repository for a user or organization

Usage:

create_repo foo
create_repo bar description='Stuff and things' homepage='example.com'
create_repo baz organization=myorg

Positional arguments

Keyword arguments

POST data may also be passed as keyword arguments: description, homepage, private, has_issues, has_wiki, has_downloads, organization, team_id, auto_init, gitignore_template

delete_repo()

Create a repository for a user or organization

Usage:

delete_repo owner repo

The currently authenticated user must have the delete_repo scope. View current scopes with the show_scopes() function.

Positional arguments

list_releases()

List releases for a repository

Usage:

list_releases org repo '\(.assets[0].name)\t\(.name.id)'

Positional arguments

Keyword arguments

release()

Get a release

Usage:

release user repo 1087855

Positional arguments

Keyword arguments

create_release()

Create a release

Usage:

create_release org repo v1.2.3
create_release user repo v3.2.1 draft=true

Positional arguments

Keyword arguments

POST data may also be passed as keyword arguments: body, draft, name, prerelease, target_commitish

delete_release()

Delete a release

Usage:

delete_release org repo 1087855

Return: 0 for success; 1 for failure.

Positional arguments

release_assets()

List release assets

Usage:

release_assets user repo 1087855

Positional arguments

Keyword arguments

upload_asset()

Upload a release asset

Note, this command requires jq to find the release upload_url.

Usage:

upload_asset username reponame 1087938 \
    foo.tar application/x-tar < foo.tar

Positional arguments

Keyword arguments

list_milestones()

List milestones for a repository

Usage:

  list_milestones someuser/somerepo
  list_milestones someuser/somerepo state=closed

Positional arguments

Keyword arguments

GitHub querystring arguments may also be passed as keyword arguments: per_page, state, sort, direction

list_issues()

List issues for the authenticated user or repository

Usage:

  list_issues
  list_issues someuser/somerepo
  list_issues someuser/somerepo state=closed labels=foo,bar

Positional arguments

Keyword arguments

GitHub querystring arguments may also be passed as keyword arguments: per_page, milestone, state, assignee, creator, mentioned, labels, sort, direction, since

user_issues()

List all issues across owned and member repositories for the authenticated user

Usage:

  user_issues
  user_issues since=2015-60-11T00:09:00Z

Positional arguments

Keyword arguments

GitHub querystring arguments may also be passed as keyword arguments: per_page, filter, state, labels, sort, direction, since

org_issues()

List all issues for a given organization for the authenticated user

Usage:

  org_issues someorg

Positional arguments

Keyword arguments

GitHub querystring arguments may also be passed as keyword arguments: per_page, filter, state, labels, sort, direction, since


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.