Giter Club home page Giter Club logo

ok.sh's Introduction

A GitHub API client library written in POSIX sh

https://github.com/whiteinge/ok.sh BSD licensed.

Requirements

  • A POSIX environment (tested against Busybox v1.19.4)
  • curl (tested against 7.32.0)

Optional requirements

  • jq http://stedolan.github.io/jq/ (tested against 1.3) If jq is not installed commands will output raw JSON; if jq is installed the output will be formatted and filtered for use with other shell tools.

Setup

Authentication credentials are read from a $HOME/.netrc file on UNIX machines or a _netrc file in %HOME% for UNIX environments under Windows. 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>

machine uploads.github.com
    login <username>
    password <token>

Or set an environment GITHUB_TOKEN=token

Configuration

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

  • OK_SH_URL=https://api.github.com Base URL for GitHub or GitHub Enterprise.
  • OK_SH_ACCEPT=application/vnd.github.v3+json The 'Accept' header to send with each request.
  • OK_SH_JQ_BIN=jq The name of the jq binary, if installed.
  • OK_SH_VERBOSE=0 The debug logging verbosity level. Same as the verbose flag.
  • OK_SH_RATE_LIMIT=0 Output current GitHub rate limit information to stderr.
  • OK_SH_DESTRUCTIVE=0 Allow destructive operations without prompting for confirmation.
  • OK_SH_MARKDOWN=1 Output some text in Markdown format.

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'
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.

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

Table of Contents

Utility and request/response commands

GitHub commands

Commands

_all_funcs

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

Keyword arguments

  • public=1

    0 do not output public functions.

  • private=1

    0 do not output private functions.

_log

A lightweight logging system based on file descriptors

Usage:

_log debug 'Starting the combobulator!'

Positional arguments

  • level="$1"

    The level for a given log message. (info or debug)

  • message="$2"

    The log message.

_helptext

Extract contiguous lines of comments and function params as help text

Indentation will be ignored. She-bangs 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

  • (stdin) The text of a function body to parse.

_format_json

Create formatted JSON from name=value pairs

Usage:

ok.sh _format_json foo=Foo bar=123 baz=true qux=Qux=Qux quux='Multi-line
string' quuz=\'5.20170918\' \
  corge="$(ok.sh _format_json grault=Grault)" \
  garply="$(ok.sh _format_json -a waldo true 3)"

Return:

{
  "garply": [
    "waldo",
    true,
    3
  ],
  "foo": "Foo",
  "corge": {
    "grault": "Grault"
  },
  "baz": true,
  "qux": "Qux=Qux",
  "quux": "Multi-line\nstring",
  "quuz": "5.20170918",
  "bar": 123
}

Tries not to quote numbers, booleans, nulls, or nested structures. Note, nested structures must be quoted since the output contains spaces.

The -a option will create an array instead of an object. This option must come directly after the _format_json command and before any operands. E.g., _format_json -a foo bar baz.

If jq is installed it will also validate the output.

Positional arguments

  • $1 - $9

    Each positional arg must be in the format of name=value which will be added to a single, flat JSON object.

_format_urlencode

URL encode and join name=value pairs

Usage:

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

Return:

foo=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:

printf '[{"foo": "One"}, {"foo": "Two"}]' | \
    ok.sh _filter_json '.[] | "\(.foo)"'
  • (stdin) JSON input.

  • _filter="$1"

    A string of jq filters to apply to the input stream.

_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

  • filename="$1"

    The full name of the file, with extension.

_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

  • message="$1"

    The message to prompt the user with.

_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

Extract common query string keyword options and assign to vars

Usage:

local qs
_opts_qs "$@"
_get "/some/path"

_request

A wrapper around making HTTP requests with curl

Usage:

# Get JSON for all issues:
_request /repos/saltstack/salt/issues

# Send a POST request; parse response using jq:
printf '{"title": "%s", "body": "%s"}\n' "Stuff" "Things" \
  | _request /some/path | jq -r '.[url]'

# Send a PUT request; parse response using jq:
printf '{"title": "%s", "body": "%s"}\n' "Stuff" "Things" \
  | _request /repos/:owner/:repo/issues method=PUT | jq -r '.[url]'

# Send a conditional-GET request:
_request /users etag=edd3a0d38d8c329d3ccc6575f17a76bb

Input

  • (stdin) Data that will be used as the request body.

Positional arguments

  • path="$1"

    The URL path for the HTTP request. Must be an absolute path that starts with a / or a full URL that starts with http(s). Absolute paths will be append to the value in $OK_SH_URL.

Keyword arguments

  • method='GET'

    The method to use for the HTTP request.

  • content_type='application/json'

    The value of the Content-Type header to use for the request.

  • etag

    An optional Etag to send as the If-None-Match header.

_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 parse using shell tools.

Usage:

# Send a request; output the response and only select response headers:
_request /some/path | _response status_code ETag Link_next

# Make request using curl; output response with select response headers;
# assign response headers to local variables:
curl -isS example.com/some/path | _response status_code status_text | {
  local status_code status_text
  read -r status_code
  read -r status_text
}

Header reformatting

  • HTTP Status

    The HTTP line is split into separate http_version, status_code, and status_text variables.

  • ETag

    The surrounding quotes are removed.

  • Link

    Each URL in the Link header is expanded with the URL type appended to the name. E.g., Link_first, Link_last, Link_next.

Positional arguments

  • $1 - $9

    Each positional arg is the name of an HTTP header. Each header value is output in the same order as each argument; each on a single line. A blank line is output for headers that cannot be found.

_get

A wrapper around _request() for common GET patterns

Will automatically follow 'next' pagination URLs in the Link header.

Usage:

_get /some/path
_get /some/path _follow_next=0
_get /some/path _follow_next_limit=200 | jq -c .

Positional arguments

  • path="$1"

    The HTTP path or URL to pass to _request().

Keyword arguments

  • _follow_next=1

    Automatically look for a 'Links' header and follow any 'next' URLs.

  • _follow_next_limit=50

    Maximum number of 'next' URLs to follow before stopping.

_post

A wrapper around _request() for common 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

  • (stdin) Optional. See the filename argument also. Data that will be used as the request body.

Positional arguments

  • path="$1"

    The HTTP path or URL to pass to _request().

Keyword arguments

  • method='POST'

    The method to use for the HTTP request.

  • filename

    Optional. See the stdin option above also. Takes precedence over any data passed as stdin and loads a file off the file system to serve as the request body.

  • mime_type

    The value of the Content-Type header to use for the request. If the filename argument is given this value will be guessed from the file extension. If the filename argument is not given (i.e., using stdin) this value defaults to application/json. Specifying this argument overrides all other defaults or guesses.

_delete

A wrapper around _request() for common DELETE patterns

Usage:

_delete '/some/url'

Return: 0 for success; 1 for failure.

Positional arguments

  • url="$1"

    The URL to send the DELETE request to.

help

Output the help text for a command

Usage:

help commandname

Positional arguments

  • fname="$1"

    Function name to search for; if omitted searches whole file.

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

  • org="$1"

    Organization GitHub login or id for which to list repos.

Keyword arguments

  • _follow_next

    Automatically look for a 'Links' header and follow any 'next' URLs.

  • _follow_next_limit

    Maximum number of 'next' URLs to follow before stopping.

  • _filter='.[] | "\(.name)\t\(.ssh_url)"'

    A jq filter to apply to the return data.

Querystring arguments may also be passed as keyword arguments:

  • per_page
  • type

org_teams

List teams

Usage:

org_teams org

Positional arguments

  • org="$1"

    Organization GitHub login or id.

Keyword arguments

  • _filter='.[] | "\(.name)\t\(.id)\t\(.permission)"'

    A jq filter to apply to the return data.

org_members

List organization members

Usage:

org_members org

Positional arguments

  • org="$1"

    Organization GitHub login or id.

Keyword arguments

  • _filter='.[] | "\(.login)\t\(.id)"'

    A jq filter to apply to the return data.

org_collaborators

List organization outside collaborators

Usage:

org_collaborators org

Positional arguments

  • org="$1"

    Organization GitHub login or id.

Keyword arguments

  • _filter='.[] | "\(.login)\t\(.id)"'

    A jq filter to apply to the return data.

org_auditlog

Interact with the Github Audit Log

Usage:

org_auditlog org

Positional arguments

  • org="$1"

    Organization GitHub login or id.

Keyword arguments

  • _filter='.[] | "\(.actor)\t\(.action)"'

    A jq filter to apply to the return data.

team_members

List team members

Usage:

team_members team_id

Positional arguments

  • team_id="$1"

    Team id.

Keyword arguments

  • _filter='.[] | "\(.login)\t\(.id)"'

    A jq filter to apply to the return data.

list_repos

List user repositories

Usage:

list_repos
list_repos user

Positional arguments

  • user="$1"

    Optional GitHub user login or id for which to list repos.

Keyword arguments

  • _filter='.[] | "\(.name)\t\(.html_url)"'

    A jq filter to apply to the return data.

Querystring arguments may also be passed as keyword arguments:

  • direction
  • per_page
  • sort
  • type

list_branches

List branches of a specified repository. ( https://developer.github.com/v3/repos/#list_branches )

Usage:

list_branches user repo

Positional arguments

GitHub user login or id for which to list branches Name of the repo for which to list branches

  • user="$1"

  • repo="$2"

Keyword arguments

  • _filter='.[] | "\(.name)"'

    A jq filter to apply to the return data.

Querystring arguments may also be passed as keyword arguments:

  • direction
  • per_page
  • sort
  • type

list_commits

List commits of a specified repository. ( https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository )

Usage:

list_commits user repo

Positional arguments

GitHub user login or id for which to list branches Name of the repo for which to list branches

list_contributors

List contributors to the specified repository, sorted by the number of commits per contributor in descending order. ( https://developer.github.com/v3/repos/#list-contributors )

Usage:

list_contributors user repo

Positional arguments

  • user="$1"

    GitHub user login or id for which to list contributors

  • repo="$2"

    Name of the repo for which to list contributors

Keyword arguments

  • _filter='.[] | "\(.login)\t\(.type)\tType:\(.type)\tContributions:\(.contributions)"'

    A jq filter to apply to the return data.

Querystring arguments may also be passed as keyword arguments:

  • direction
  • per_page
  • sort
  • type

list_collaborators

List collaborators to the specified repository, sorted by the number of commits per collaborator in descending order. ( https://developer.github.com/v3/repos/#list-collaborators )

Usage:

list_collaborators someuser/somerepo

Positional arguments GitHub user login or id for which to list collaborators Name of the repo for which to list collaborators

  • repo="$1"

Keyword arguments

  • _filter='.[] | "\(.login)\t\(.type)\tType:\(.type)\tPermissions:\(.permissions)"'

    A jq filter to apply to the return data.

Querystring arguments may also be passed as keyword arguments:

  • direction
  • per_page
  • sort
  • type

list_hooks

List webhooks from the specified repository. ( https://developer.github.com/v3/repos/hooks/#list-hooks )

Usage:

list_hooks owner/repo

Positional arguments

  • repo="$1"

    Name of the repo for which to list contributors Owner is mandatory, like 'owner/repo'

  • _filter='.[] | "\(.name)\t\(.config.url)"'

    A jq filter to apply to the return data.

list_gists

List gists for the current authenticated user or a specific user

https://developer.github.com/v3/gists/#list-a-users-gists

Usage:

list_gists
list_gists <username>

Positional arguments

  • username="$1"

    An optional user to filter listing

Keyword arguments

  • _follow_next

    Automatically look for a 'Links' header and follow any 'next' URLs.

  • _follow_next_limit

    Maximum number of 'next' URLs to follow before stopping.

  • _filter='.[] | "\(.id)\t\(.description)"'

    A jq filter to apply to the return data.

public_gists

List public gists

https://developer.github.com/v3/gists/#list-all-public-gists

Usage:

public_gists

Keyword arguments

  • _follow_next

    Automatically look for a 'Links' header and follow any 'next' URLs.

  • _follow_next_limit

    Maximum number of 'next' URLs to follow before stopping.

  • _filter='.[] | "\(.id)\t\(.description)"'

    A jq filter to apply to the return data.

gist

Get a single gist

https://developer.github.com/v3/gists/#get-a-single-gist

Usage:

get_gist

Positional arguments

  • gist_id="$1"

    ID of gist to fetch.

Keyword arguments

  • _filter='.files | keys | join(", ")'

    A jq filter to apply to the return data.

add_collaborator

Add a collaborator to a repository

Usage:

add_collaborator someuser/somerepo collaboratoruser permission

Positional arguments

  • repo="$1"

    A GitHub repository.

  • collaborator="$2"

    A new collaborator.

  • permission="$3"

    The permission level for this collaborator. One of push, pull, admin. The pull and admin permissions are valid for organization repos only.

Keyword arguments

  • _filter='"\(.name)\t\(.color)"'

    A jq filter to apply to the return data.

delete_collaborator

Delete a collaborator to a repository

Usage:

delete_collaborator someuser/somerepo collaboratoruser permission

Positional arguments

  • repo="$1"

    A GitHub repository.

  • collaborator="$2"

    A new collaborator.

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

  • name="$1"

    Name of the new repo

Keyword arguments

  • _filter='"\(.name)\t\(.html_url)"'

    A jq filter to apply to the return data.

POST data may also be passed as keyword arguments:

  • auto_init,
  • description
  • gitignore_template
  • has_downloads
  • has_issues
  • has_wiki,
  • homepage
  • organization
  • private
  • team_id

delete_repo

Delete 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

  • owner="$1"

    Name of the new repo

  • repo="$2"

    Name of the new repo

fork_repo

Fork a repository from a user or organization to own account or organization

Usage:

fork_repo owner repo

Positional arguments

  • owner="$1"

    Name of existing user or organization

  • repo="$2"

    Name of the existing repo

Keyword arguments

  • _filter='"\(.clone_url)\t\(.ssh_url)"'

    A jq filter to apply to the return data.

POST data may also be passed as keyword arguments:

  • organization (The organization to clone into; default: your personal account)

list_releases

List releases for a repository

https://developer.github.com/v3/repos/releases/#list-releases-for-a-repository

Usage:

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

Positional arguments

  • owner="$1"

    A GitHub user or organization.

  • repo="$2"

    A GitHub repository.

Keyword arguments

  • _filter='.[] | "\(.name)\t\(.tag_name)\t\(.id)\t\(.html_url)"'

    A jq filter to apply to the return data.

release

Get a release

https://developer.github.com/v3/repos/releases/#get-a-single-release

Usage:

release user repo 1087855

Positional arguments

  • owner="$1"

    A GitHub user or organization.

  • repo="$2"

    A GitHub repository.

  • release_id="$3"

    The unique ID of the release; see list_releases.

Keyword arguments

  • _filter='"\(.author.login)\t\(.published_at)"'

    A jq filter to apply to the return data.

create_release

Create a release

https://developer.github.com/v3/repos/releases/#create-a-release

Usage:

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

Positional arguments

  • owner="$1"

    A GitHub user or organization.

  • repo="$2"

    A GitHub repository.

  • tag_name="$3"

    Git tag from which to create release.

Keyword arguments

  • _filter='"\(.name)\t\(.id)\t\(.html_url)"'

    A jq filter to apply to the return data.

POST data may also be passed as keyword arguments:

  • body
  • draft
  • name
  • prerelease
  • target_commitish

edit_release

Edit a release

https://developer.github.com/v3/repos/releases/#edit-a-release

Usage:

edit_release org repo 1087855 name='Foo Bar 1.4.6'
edit_release user repo 1087855 draft=false

Positional arguments

  • owner="$1"

    A GitHub user or organization.

  • repo="$2"

    A GitHub repository.

  • release_id="$3"

    The unique ID of the release; see list_releases.

Keyword arguments

  • _filter='"\(.tag_name)\t\(.name)\t\(.html_url)"'

    A jq filter to apply to the return data.

POST data may also be passed as keyword arguments:

  • tag_name
  • body
  • draft
  • name
  • prerelease
  • target_commitish

delete_release

Delete a release

https://developer.github.com/v3/repos/releases/#delete-a-release

Usage:

delete_release org repo 1087855

Return: 0 for success; 1 for failure.

Positional arguments

  • owner="$1"

    A GitHub user or organization.

  • repo="$2"

    A GitHub repository.

  • release_id="$3"

    The unique ID of the release; see list_releases.

release_assets

List release assets

https://developer.github.com/v3/repos/releases/#list-assets-for-a-release

Usage:

release_assets user repo 1087855

Example of downloading release assets:

ok.sh release_assets <user> <repo> <release_id> \
        _filter='.[] | .browser_download_url' \
    | xargs -L1 curl -L -O

Example of the multi-step process for grabbing the release ID for a specific version, then grabbing the release asset IDs, and then downloading all the release assets (whew!):

username='myuser'
repo='myrepo'
release_tag='v1.2.3'
ok.sh list_releases "$myuser" "$myrepo" \
    | awk -F'\t' -v tag="$release_tag" '$2 == tag { print $3 }' \
    | xargs -I{} ./ok.sh release_assets "$myuser" "$myrepo" {} \
        _filter='.[] | .browser_download_url' \
    | xargs -L1 curl -n -L -O

Positional arguments

  • owner="$1"

    A GitHub user or organization.

  • repo="$2"

    A GitHub repository.

  • release_id="$3"

    The unique ID of the release; see list_releases.

Keyword arguments

  • _filter='.[] | "\(.id)\t\(.name)\t\(.updated_at)"'

    A jq filter to apply to the return data.

upload_asset

Upload a release asset

https://developer.github.com/v3/repos/releases/#upload-a-release-asset

Usage:

upload_asset https://<upload-url> /path/to/file.zip

The upload URL can be gotten from release(). There are multiple steps required to upload a file: get the release ID, get the upload URL, parse the upload URL, then finally upload the file. For example:

USER="someuser"
REPO="somerepo"
TAG="1.2.3"
FILE_NAME="foo.zip"
FILE_PATH="/path/to/foo.zip"

# Create a release then upload a file:
ok.sh create_release "$USER" "$REPO" "$TAG" _filter='.upload_url' \
    | sed 's/{.*$/?name='"$FILE_NAME"'/' \
    | xargs -I@ ok.sh upload_asset @ "$FILE_PATH"

# Find a release by tag then upload a file:
ok.sh list_releases "$USER" "$REPO" \
    | awk -v "tag=$TAG" -F'\t' '$2 == tag { print $3 }' \
    | xargs -I@ ok.sh release "$USER" "$REPO" @ _filter='.upload_url' \
    | sed 's/{.*$/?name='"$FILE_NAME"'/' \
    | xargs -I@ ok.sh upload_asset @ "$FILE_PATH"

Positional arguments

  • upload_url="$1"

The parsed upload_url returned from GitHub.

  • file_path="$2"

    A path to the file that should be uploaded.

Keyword arguments

  • _filter='"\(.state)\t\(.browser_download_url)"'

    A jq filter to apply to the return data.

Also any other keyword arguments accepted by _post().

delete_asset

Delete a release asset

https://docs.github.com/en/rest/reference/releases#delete-a-release-asset

Usage:

delete_asset user repo 51955388

Example of deleting release assets:

ok.sh release_assets <user> <repo> <release_id> \
        _filter='.[] | .id' \
    | xargs -L1 ./ok.sh delete_asset "$myuser" "$myrepo"

Example of the multi-step process for grabbing the release ID for a specific version, then grabbing the release asset IDs, and then deleting all the release assets (whew!):

username='myuser'
repo='myrepo'
release_tag='v1.2.3'
ok.sh list_releases "$myuser" "$myrepo" \
    | awk -F'\t' -v tag="$release_tag" '$2 == tag { print $3 }' \
    | xargs -I{} ./ok.sh release_assets "$myuser" "$myrepo" {} \
        _filter='.[] | .id' \
    | xargs -L1 ./ok.sh -y delete_asset "$myuser" "$myrepo"

Positional arguments

  • owner="$1"

    A GitHub user or organization.

  • repo="$2"

    A GitHub repository.

  • asset_id="$3"

    The unique ID of the release asset; see release_assets.

list_milestones

List milestones for a repository

Usage:

list_milestones someuser/somerepo
list_milestones someuser/somerepo state=closed

Positional arguments

  • repository="$1"

    A GitHub repository.

Keyword arguments

  • _follow_next

    Automatically look for a 'Links' header and follow any 'next' URLs.

  • _follow_next_limit

    Maximum number of 'next' URLs to follow before stopping.

  • _filter='.[] | "\(.number)\t\(.open_issues)/\(.closed_issues)\t\(.title)"'

    A jq filter to apply to the return data.

GitHub querystring arguments may also be passed as keyword arguments:

  • direction
  • per_page
  • sort
  • state

create_milestone

Create a milestone for a repository

Usage:

create_milestone someuser/somerepo MyMilestone

create_milestone someuser/somerepo MyMilestone \
    due_on=2015-06-16T16:54:00Z \
    description='Long description here
that spans multiple lines.'

Positional arguments

  • repo="$1"

    A GitHub repository.

  • title="$2"

    A unique title.

Keyword arguments

  • _filter='"\(.number)\t\(.html_url)"'

    A jq filter to apply to the return data.

Milestone options may also be passed as keyword arguments:

  • description
  • due_on
  • state

list_issue_comments

List comments of a specified issue. ( https://developer.github.com/v3/issues/comments/#list-issue-comments )

Usage:

list_issue_comments someuser/somerepo number

Positional arguments

GitHub owner login or id for which to list branches Name of the repo for which to list branches Issue number

  • repo="$1"

  • number="$2"

add_comment

Add a comment to an issue

Usage:

add_comment someuser/somerepo 123 'This is a comment'

Positional arguments

  • repository="$1"

    A GitHub repository

  • number="$2"

    Issue Number

  • comment="$3"

    Comment to be added

Keyword arguments

  • _filter='"\(.id)\t\(.html_url)"'

    A jq filter to apply to the return data.

list_commit_comments

List comments of a specified commit. ( https://developer.github.com/v3/repos/comments/#list-commit-comments )

Usage:

list_commit_comments someuser/somerepo sha

Positional arguments

GitHub owner login or id for which to list branches Name of the repo for which to list branches Commit SHA

  • repo="$1"

  • sha="$2"

add_commit_comment

Add a comment to a commit

Usage:

add_commit_comment someuser/somerepo 123 'This is a comment'

Positional arguments

  • repository="$1"

    A GitHub repository

  • hash="$2"

    Commit hash

  • comment="$3"

    Comment to be added

Keyword arguments

  • _filter='"\(.id)\t\(.html_url)"'

    A jq filter to apply to the return data.

close_issue

Close an issue

Usage:

close_issue someuser/somerepo 123

Positional arguments

  • repository="$1"

    A GitHub repository

  • number="$2"

    Issue Number

Keyword arguments

  • _filter='"\(.id)\t\(.state)\t\(.html_url)"'

    A jq filter to apply to the return data.

POST data may also be passed as keyword arguments:

  • assignee
  • labels
  • milestone

list_issues

List issues for the authenticated user or repository

Usage:

list_issues
list_issues someuser/somerepo
list_issues <any of the above> state=closed labels=foo,bar

Positional arguments

user or user/repository

Keyword arguments

  • _follow_next

    Automatically look for a 'Links' header and follow any 'next' URLs.

  • _follow_next_limit

    Maximum number of 'next' URLs to follow before stopping.

  • _filter='.[] | "\(.number)\t\(.title)"'

    A jq filter to apply to the return data.

GitHub querystring arguments may also be passed as keyword arguments:

  • assignee
  • creator
  • direction
  • labels
  • mentioned
  • milestone
  • per_page
  • since
  • sort
  • state

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

Keyword arguments

  • _follow_next

    Automatically look for a 'Links' header and follow any 'next' URLs.

  • _follow_next_limit

    Maximum number of 'next' URLs to follow before stopping.

  • _filter='.[] | "\(.repository.full_name)\t\(.number)\t\(.title)"'

    A jq filter to apply to the return data.

GitHub querystring arguments may also be passed as keyword arguments:

  • direction
  • filter
  • labels
  • per_page
  • since
  • sort
  • state

create_issue

Create an issue

Usage:

create_issue owner repo 'Issue title' body='Add multiline body
content here' labels="$(./ok.sh _format_json -a foo bar)"

Positional arguments

  • owner="$1"

    A GitHub repository.

  • repo="$2"

    A GitHub repository.

  • title="$3"

    A GitHub repository.

Keyword arguments

  • _filter='"\(.id)\t\(.number)\t\(.html_url)"'

    A jq filter to apply to the return data.

Additional issue fields may be passed as keyword arguments:

  • body (string)
  • assignee (string)
  • milestone (integer)
  • labels (array of strings)
  • assignees (array of strings)

org_issues

List all issues for a given organization for the authenticated user

Usage:

org_issues someorg

Positional arguments

  • org="$1"

    Organization GitHub login or id.

Keyword arguments

  • _follow_next

    Automatically look for a 'Links' header and follow any 'next' URLs.

  • _follow_next_limit

    Maximum number of 'next' URLs to follow before stopping.

  • _filter='.[] | "\(.number)\t\(.title)"'

    A jq filter to apply to the return data.

GitHub querystring arguments may also be passed as keyword arguments:

  • direction
  • filter
  • labels
  • per_page
  • since
  • sort
  • state

list_starred

List starred repositories

Usage:

list_starred
list_starred user

Positional arguments

  • user="$1"

    Optional GitHub user login or id for which to list the starred repos.

Keyword arguments

  • _filter='.[] | "\(.name)\t\(.html_url)"'

    A jq filter to apply to the return data.

Querystring arguments may also be passed as keyword arguments:

  • direction
  • per_page
  • sort
  • type

list_my_orgs

List your organizations

Usage:

list_my_orgs

Keyword arguments

  • _follow_next

    Automatically look for a 'Links' header and follow any 'next' URLs.

  • _follow_next_limit

    Maximum number of 'next' URLs to follow before stopping.

  • _filter='.[] | "\(.login)\t\(.id)"'

    A jq filter to apply to the return data.

list_orgs

List all organizations

Usage:

list_orgs

Keyword arguments

  • _follow_next

    Automatically look for a 'Links' header and follow any 'next' URLs.

  • _follow_next_limit

    Maximum number of 'next' URLs to follow before stopping.

  • _filter='.[] | "\(.login)\t\(.id)"'

    A jq filter to apply to the return data.

list_users

List all users

Usage:

list_users

Keyword arguments

  • _follow_next

    Automatically look for a 'Links' header and follow any 'next' URLs.

  • _follow_next_limit

    Maximum number of 'next' URLs to follow before stopping.

  • _filter='.[] | "\(.login)\t\(.id)"'

    A jq filter to apply to the return data.

labels

List available labels for a repository

Usage:

labels someuser/somerepo

Positional arguments

  • repo="$1"

    A GitHub repository.

Keyword arguments

  • _follow_next

    Automatically look for a 'Links' header and follow any 'next' URLs.

  • _follow_next_limit

    Maximum number of 'next' URLs to follow before stopping.

  • _filter='.[] | "\(.name)\t\(.color)"'

    A jq filter to apply to the return data.

add_label

Add a label to a repository

Usage:

add_label someuser/somerepo LabelName color

Positional arguments

  • repo="$1"

    A GitHub repository.

  • label="$2"

    A new label.

  • color="$3"

    A color, in hex, without the leading #.

Keyword arguments

  • _filter='"\(.name)\t\(.color)"'

    A jq filter to apply to the return data.

update_label

Update a label

Usage:

update_label someuser/somerepo OldLabelName \
    label=NewLabel color=newcolor

Positional arguments

  • repo="$1"

    A GitHub repository.

  • label="$2"

    The name of the label which will be updated

Keyword arguments

  • _filter='"\(.name)\t\(.color)"'

    A jq filter to apply to the return data.

Label options may also be passed as keyword arguments, these will update the existing values:

  • color
  • name

add_team_repo

Add a team repository

Usage:

add_team_repo team_id organization repository_name permission

Positional arguments

  • team_id="$1"

    Team id to add repository to

  • organization="$2"

    Organization to add repository to

  • repository_name="$3"

    Repository name to add

  • permission="$4"

    Permission to grant: pull, push, admin

  • url="/teams/$team_id}/repos/${organization}/${repository_name}"

list_pulls

Lists the pull requests for a repository

Usage:

list_pulls user repo

Positional arguments

  • owner="$1"

    A GitHub owner.

  • repo="$2"

    A GitHub repository.

Keyword arguments

  • _follow_next

    Automatically look for a 'Links' header and follow any 'next' URLs.

  • _follow_next_limit

    Maximum number of 'next' URLs to follow before stopping.

  • _filter='.[] | "\(.number)\t\(.user.login)\t\(.head.repo.clone_url)\t\(.head.ref)"'

    A jq filter to apply to the return data.

create_pull_request

Create a pull request for a repository

Usage:

create_pull_request someuser/somerepo title head base

create_pull_request someuser/somerepo title head base body='Description here.'

Positional arguments

  • repo="$1"

    A GitHub repository.

  • title="$2"

    A title.

  • head="$3"

    A head.

  • base="$4"

    A base.

Keyword arguments

  • _filter='"\(.number)\t\(.html_url)"'

    A jq filter to apply to the return data.

Pull request options may also be passed as keyword arguments:

  • body
  • maintainer_can_modify

update_pull_request

Update a pull request for a repository

Usage:

update_pull_request someuser/somerepo number title='New title' body='New body'

Positional arguments

  • repo="$1"

    A GitHub repository.

  • number="$2"

    A pull request number.

Keyword arguments

  • _filter='"\(.number)\t\(.html_url)"'

    A jq filter to apply to the return data.

Pull request options may also be passed as keyword arguments:

  • base
  • body
  • maintainer_can_modify
  • state (either open or closed)
  • title

transfer_repo

Transfer a repository to a user or organization

Usage:

transfer_repo owner repo new_owner
transfer_repo owner repo new_owner team_ids='[ 12, 345 ]'

Positional arguments

  • owner="$1"

    Name of the current owner

  • repo="$2"

    Name of the current repo

  • new_owner="$3"

    Name of the new owner

Keyword arguments

  • _filter='"\(.name)"'

    A jq filter to apply to the return data.

POST data may also be passed as keyword arguments:

  • team_ids

archive_repo

Archive a repo

Usage:

archive_repo owner/repo

Positional arguments

  • repo="$1"

    A GitHub repository.

  • _filter='"\(.name)\t\(.html_url)"'

    A jq filter to apply to the return data.

ok.sh's People

Contributors

arturklauser avatar deinspanjer avatar dubiouscript avatar dx0eu avatar esdrasedu avatar flaix avatar folknor avatar frankwis avatar fzs avatar goruha avatar islamsalah avatar laurentgoderre avatar mlbright avatar noam-almog avatar robrankin avatar royopa avatar sgerber-hyperanna avatar szepeviktor avatar unlearn avatar utahdave avatar whiteinge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ok.sh's Issues

no way to create_issue?

From reading the docs and source to ok.sh, I didn't see any way to create an issue? I'm looking to file an issue for every warning in my code; I think I would be able to do so with that.

upload_asset with Upload URL error

I can create a release but when I try to upload a asset to release run

./scripts/ok.sh -v upload_asset $USER $REPO 13452549 javadoc.jar application/x-tar < ./build/libs/javadoc.jar

in run into

parse error: Invalid numeric literal at line 1, column 9
jq parse error; invalid JSON.
ok.sh INFO: Remaining next link follows: 50
./scripts/ok.sh: line 1652: upload_url: Upload URL could not be retrieved.

I use jq version jq-1.5

Any ideas ?

About authentication (netrc), add an environment for authentication.

Now ok.sh uses .netrc file for authorization verification, This is available in most cases.

But in some special cases, this doesn't work very well. like Travis CI.

If Travis CI set a no display value environment, unable to generate .netrc file. and then call some api will return Client Error: 401 Unauthorized

Is it possible to add an environment variable?

like this

https://github.com/whiteinge/ok.sh/blob/master/ok.sh#L697

curl -nsSig \
    -H "Accept: ${OK_SH_ACCEPT}" \
    -H "Content-Type: ${content_type}" \
    ${etag:+-H "If-None-Match: \"${etag}\""} \
    ${GITHUB_TOKEN:+-H "Authorization token ${GITHUB_TOKEN}"} \
    ${has_stdin:+--data-binary @-} \
    ${trace_curl:+--trace-ascii /dev/stderr} \
    -X "${method}" \
    "${path}"

Web site

Set up GitHub Pages web site with usage & examples.

[0.2.0] Syntax errors when creating repo

On Kubuntu 14.04, when I try to create a repo, I get these errors:

$ octokit.sh create_repo testing_octokit
/home/user/bin/octokit.sh: 397: local: |: bad variable name
/home/user/bin/octokit.sh: 577: /home/user/bin/octokit.sh: [[: not found

I guess it is because the shebang is #!/usr/bin/env sh and sh does not support local or [[.

When I run it with bash, I get another error:

$ bash octokit.sh create_repo testing_octokit
Client Error: 422 Unprocessable Entity

Fix Busybox compatibility (or come up with another way to make a POSIX-like env)

I used to test this against Busybox installed to a local directory, sandboxed via env -i. I know Busybox isn't exactly POSIX but it's pretty close, and keep the POSIX docs nearby when you're wondering about a particular flag or command. Anyway I can't think of a better way to get a near-POSIX environment set up. (Suggestions very welcome if someone has an idea here.)

It's been a while since I've done that and a few non-compatible things have snuck in. Busybox doesn't seem to have pr (even though it's POSIX), and there's a syntax error (unclosed }) somewhere in the file that Busybox's sh is choking on that dash is otherwise fine with.

So, either:

  • Come up with a different way to make a POSIX env for testing and remove mention of Busybox from the README;
  • or, Fix Busybox compatibility.

Create tag as part of release?

Github's releases UI allows you to create new tags as part of creating a new release. Could this functionality also be exposed via the create_release command?

what is a direction querystring argument?

I'm struggling to find information about this. What values can I inject?

Edit: I assume it's ordering. But it should be clarified in the docs if that is the case.

Normalize user & repo usage?

Some API calls use a single user/repo arg and some use separate user & repo args. This is annoying to work with because you have to look up the docs for each. Should ok.sh normalize on one format?

Add support for 422 responses

Would be helpful to display the error message from GitHub at the CLI. E.g.

{
  "message": "Validation Failed",
  "errors": [
    {
      "resource": "Milestone",
      "code": "missing_field",
      "field": "title"
    },
    {
      "resource": "Milestone",
      "code": "missing_field",
      "field": "slug"
    }
  ],
  "documentation_url": "https://developer.github.com/v3/issues/milestones/#create-a-milestone"
}

Tag name that looks like a float not treated as string

So I try to use create_release with these arguments: stellaris-mods testing 5.20170918 body="* Test\n * Test2"

And I get this result:

0000: {.  "message": "Invalid request.\n\nFor 'properties/tag_name', 5
0040: .20170918 is not a string.",.  "documentation_url": "https://dev
0080: eloper.github.com/v3".}.

Sent data:

=> Send data, 109 bytes (0x6d)
0000: {"tag_name": 5.20170918, "body": "* Updated readme.md with chang
0040: es from steam.bbcode.\n* Skogfisk eplepai."}.
== Info: upload completely sent off: 109 out of 109 bytes

I get the same result if I quote the argument on the command line, like:
stellaris-mods testing '5.20170918' body="* Test\n * Test2"

I have not tried using " to quote it, and I don't have time to do so right now (because I deleted the repository already and I need to go make dinner).

Add meta data

Please add meta data to ok.sh.
For example

#!/bin/bash
#
# One line description for this script.
#
# VERSION       :semver
# DATE          :2017-12-31
# URL           :https://github.com/szepeviktor/debian-server-tools
# AUTHOR        :Viktor Szépe <[email protected]>
# LICENSE       :The MIT License (MIT)
# BASH-VERSION  :4.2+
# DEPENDS       :apt-get install package
# REFS          :url
# DOCS          :url
# SOURCE        :url
# UPSTREAM      :url
# LOCATION      :/usr/local/sbin/script.sh
# OWNER         :root:root
# PERMISSION    :0755
# SYMLINK       :/usr/local/sbin/alias.sh
# CRON-HOURLY   :/usr/local/sbin/script.sh
# CRON-DAILY    :/usr/local/sbin/script.sh
# CRON-WEEKLY   :/usr/local/sbin/script.sh
# CRON-MONTHLY  :/usr/local/sbin/script.sh | mailx -E -s "subject" root
# CRON.D        :2 2<-->* * *<->root<-->/usr/local/sbin/script.sh
# CONFIG        :~/.config/script/configuration

ARM / Raspberry PI - Runtime errors

  1. JQ is installed:
raspberrypi2> jq
jq - commandline JSON processor [version ]
Usage: jq [options] <jq filter> [file...]

        jq is a tool for processing JSON inputs, applying the..
            ....

Running any command:

qx@raspberrypi2 ~ $ ok.sh list_releases toyfoundry rebadge
/usr/local/bin/ok.sh: 399: local: |: bad variable name

With debug:

qx@raspberrypi2 ~ $ ok.sh org_repos toyfoundry
ok.sh DEBUG: Running command org_repos.
ok.sh DEBUG: Formatting 0 parameters as urlencoded
/usr/local/bin/ok.sh: 399: local: |: bad variable name
ok.sh DEBUG: Processing response.
ok.sh DEBUG: Response status is: 200 OK
ok.sh DEBUG: Outputting requested header 'status_code'.
ok.sh DEBUG: Outputting requested header 'status_text'.
ok.sh DEBUG: Outputting requested header 'Link_next'.
ok.sh INFO: Remaining next link follows: 50
ok.sh DEBUG: Command org_repos exited with 0.

Any ideas would be appreciated!

POSIX compliance; ok shells.

Couple things:

  • local is a bashism and definitely not POSIX. It doesn't exist in compliant shells like ksh, yash, many others. Interestingly ok.sh is ok in oksh.

  • The shebang is not POSIX, either, strictly speaking. You can begin a script with a colon instead.

ok.sh: line 200: local: not found
ok.sh: line 201: local: not found
ok.sh: line 202: local: not found
ok.sh: line 203: local: not found
ok.sh: line 204: local: not found
ok.sh: line 205: local: not found
ok.sh: line 206: local: not found
ok.sh: line 208: local: not found
ok.sh: line 154: local: not found
ok.sh: line 156: local: not found
No command given. Available commands:

$
  • toybox is much more compliant than busybox, fwiw.

Gl

Describe the bug

A clear and concise description of what the bug is and what the expected
behavior is.

Include logs

  • Run ok.sh with the -vvv flag to look for any potential problems in the
    HTTP response from GitHub. Feel free to attach that output but remember to
    remove the Authorization header first!
  • Run ok.sh -x [...command here...] 2> ok-shdebug.log and attach that file.

Environment (please complete the following information)

  • ok.sh release.

  • curl version.

  • jq version.

  • What operating system and version.

  • What shell.

    If you are unsure, download
    whatshell.sh and run
    /usr/bin/env sh /path/to/whatshell.sh.

Additional context

Add any other context about the problem here.

README

Extract help-text out into generated (?) README file.

idkwtf list_issues = curl: (6) Could not resolve host: api.github.com<https ??

./ok.sh list_issues nixos/nix

...

bash -x ./ok.sh -vvv list_issues nixos/nix 2>&1 | tee "$log_file"
..

<= Recv header, 153 bytes (0x99)
0000: Link: <https://api.github.com/repositories/3386088/issues?page=2
0040: >; rel="next", <https://api.github.com/repositories/3386088/issu
0080: es?page=33>; rel="last"
+ read -r hdr val
+ '[' Link = $'\r' ']'
+ val='<https://api.github.com/repositories/3386088/issues?page=2>; rel="next", <https://api.github.com/repositories/3386088/issues?p
age=33>; rel="last"'
+ case "$hdr" in
++ printf %s '<https://api.github.com/repositories/3386088/issues?page=2>; rel="next", <https://api.github.com/repositories/3386088/issues?page=33>; rel="last"'
++ awk '
                BEGIN { RS=", "; FS="; "; OFS=": " }
                {
                    sub(/^rel="/, "", $2); sub(/"$/, "", $2)
                    sub(/^[[:space:]]*</, "", $1); sub(/>$/, "", $1)
                    print "Link_" $2, $1
                }'
+ headers='http_version: 1.1
status_code: 200
status_text: OK
Server: GitHub.com
Date: Thu, 22 Nov 2018 16:02:38 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 93284
Status: 200 OK
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 55
X-RateLimit-Reset: 1542905660
Cache-Control: public, max-age=60, s-maxage=60
Vary: Accept
ETag: 9dc7bc9fda118e6e7066512ebc3da67d
X-GitHub-Media-Type: github.v3; format=json
Link_next: <https://api.github.com/repositories/3386088/issues?page=2
Link_last: <https://api.github.com/repositories/3386088/issues?page=33
realpath $(which awk )
/usr/bin/mawk

mawk -W version
mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan

messing about abit
i guess this is the expected result !!

printf %s '<https://api.github.com/repositories/3386088/issues?page=2>; rel="next", <https://api.github.com/repositories/3386088/issues?page=33>; rel="last"' | awk '
                BEGIN { RS=", "; FS="; "; OFS=": " }
                {
                    sub(/^rel="/, "", $2); sub(/"$/, "", $2)
                    sub(/^ *</, "", $1); sub(/>$/, "", $1)
                    print "Link_" $2, $1
                }'
Link_next: https://api.github.com/repositories/3386088/issues?page=2
Link_last: https://api.github.com/repositories/3386088/issues?page=33

... so this appears a
problem with mawk /^[[:space:]]*</

upload_asset pipes HTTP headers into jq

When running upload_asset, jq reports an error:

$ ./ok.sh upload_asset https://uploads.github.com/repos/ArturKlauser/raspberrypi-rstudio/releases/23039592/assets?name=foo1 ok.sh mime_type=application/octet-stream
parse error: Invalid numeric literal at line 1, column 9
jq parse error; invalid JSON.

The error goes away when -q is specified.
Some digging shows that apparently the HTTP headers are piped into jq before the actual json data:

$ printf ':\ncat -\n' > myjq; chmod 755 myjq
$ OK_SH_JQ_BIN=./myjq ~/Downloads/ok.sh upload_asset https://uploads.github.com/repos/ArturKlauser/raspberrypi-rstudio/releases/23039592/assets?name=foo2 ok.sh mime_type=application/octet-stream
HTTP/1.1 201 Created
Cache-Control: no-cache
Content-Security-Policy: default-src 'none'
Content-Type: application/json; charset=utf-8
Etag: W/"75c6982651342ea7db8fa9949fc7b3b4"
Last-Modified: Wed, 22 Jan 2020 14:59:26 GMT
Strict-Transport-Security: max-age=31557600
Vary: Accept, Authorization, Cookie, X-GitHub-OTP
X-Accepted-Oauth-Scopes: repo
X-Content-Type-Options: nosniff
X-Frame-Options: deny
X-Github-Media-Type: github.v3; format=json
X-Oauth-Scopes: repo
X-Xss-Protection: 1; mode=block
Date: Wed, 22 Jan 2020 14:59:26 GMT
Transfer-Encoding: chunked
X-GitHub-Request-Id: CE13:5182:68E29:8648C:5E28634C

{"url":"https://api.github.com/repos/ArturKlauser/raspberrypi-rstudio/releases/assets/17506513","id":17506513,"node_id":"MDEyOlJlbGVhc2VBc3NldDE3NTA2NTEz","name":"foo2","label":"","uploader":{"login":"ArturKlauser","id":4790123,"node_id":"MDQ6VXNlcjQ3OTAxMjM=","avatar_url":"https://avatars0.githubusercontent.com/u/4790123?v=4","gravatar_id":"","url":"https://api.github.com/users/ArturKlauser","html_url":"https://github.com/ArturKlauser","followers_url":"https://api.github.com/users/ArturKlauser/followers","following_url":"https://api.github.com/users/ArturKlauser/following{/other_user}","gists_url":"https://api.github.com/users/ArturKlauser/gists{/gist_id}","starred_url":"https://api.github.com/users/ArturKlauser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ArturKlauser/subscriptions","organizations_url":"https://api.github.com/users/ArturKlauser/orgs","repos_url":"https://api.github.com/users/ArturKlauser/repos","events_url":"https://api.github.com/users/ArturKlauser/events{/privacy}","received_events_url":"https://api.github.com/users/ArturKlauser/received_events","type":"User","site_admin":false},"content_type":"application/octet-stream","state":"uploaded","size":60861,"download_count":0,"created_at":"2020-01-22T14:59:25Z","updated_at":"2020-01-22T14:59:26Z","browser_download_url":"https://github.com/ArturKlauser/raspberrypi-rstudio/releases/download/untagged-dc669712e7a6ef40f473/foo2"}

Include logs

  • Run ok.sh -x [...command here...] 2> ok-shdebug.log and attach that file.

Environment (please complete the following information)

  • ok.sh release
    • 0.5.1, same happens on HEAD
  • curl version
    • curl 7.64.1 (x86_64-apple-darwin19.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.39.2, Release-Date: 2019-03-27
  • jq version.
    • jq-1.6
  • What operating system and version.
    • MacOS Catalina 10.15.2
  • What shell.
    • GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin19)

ok-shdebug.log

No usable output from script

Likely a user problem and not an issue. I am not able to get any useful output from the tool.

Following the one example in the wiki
ok.sh list_repos octocat _filter='.[] | select(.fork == false) | .clone_url'
returns nothing (with or without the filter).
adding -v

+ curl -nsSi -H Accept: application/vnd.github.v3+json -H Content-Type: application/json -X GET https://api.github.com/users/octocat/repos?AWKLIBPATH=%2Fusr%2Flib%2Fx86%5F64%2Dlinux%2Dgnu%2Fgawk
+ set +x
ok.sh INFO: Follow_next: 1
ok.sh INFO: Remaining next link follows: 50

once I add -vvv I get lots of json output but this is hardly usable.
I'm not sure if I am doing something wrong or if I misunderstood what the expected output should be. Any help would be appreciated.

upload_asset error with organization

Hi,

I'm having a problem using the upload_asset command with a github organization.

Here is the output of -vvv: https://hastebin.com/iquqitoqep
And this is the tail end of -vvv -j: https://hastebin.com/itutoribat
The first one has been edited heavily to remove the zip binary and ssl data, just for ease of reading.
Second one is just the end, mostly so you can see this:

/home/folk/.local/bin/ok.sh: 1561: local: "url":: bad variable name

Here is the relevant line from my lua script:
oksh("-vvv", "-j", "upload_asset", userId, repo, id, zip, "filename=" .. zip, "mime_type=application/zip")
userId = stellaris-mods
repo = test for the first paste, testing on the short 2nd paste
zip = folk_testmod.zip

My head is fried at the moment, hopefully I can take a closer look soon, and come back with some more information.

Tests

The basic (non-GitHub, non-HTTP-request) functionality should be friendly for unit testing. The HTTP requests should be covered by a couple basic integration tests.

I don't think I'll test the actual GitHub-centric functions because there's not a ton of value there if the other things are working right. Plus I'd have to send actual requests against the GitHub API to do so. Feedback welcome.

Reformat _filters to use @tsv for readability?

Pros:

  • It's a good bit more readable.

Cons:

  • Code churn for no functional reason.
  • User _filter overrides can already use this syntax.
 ok.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ok.sh b/ok.sh
index 4bf3b97..87407e4 100755
--- a/ok.sh
+++ b/ok.sh
@@ -1734,7 +1734,7 @@ list_releases() {
     #
     # Keyword arguments
     #
-    local _filter='.[] | "\(.name)\t\(.tag_name)\t\(.id)\t\(.html_url)"'
+    local _filter='.[] | [.name, .tag_name, .id, .html_url] | @tsv'
     #   A jq filter to apply to the return data.
 
     shift 2

repo creation fails

Describe the bug

As of 502011c, creating a repo with ok.sh create_repo foo fails with:

martinmac:ok.sh brightm$ ./ok.sh create_repo foo
awk: newline in string OK_SH_ACCEPT
OK_SH_U... at source line 1
awk: newline in string OK_SH_ACCEPT
OK_SH_U... at source line 1
awk: newline in string OK_SH_ACCEPT
OK_SH_U... at source line 1
Client Error: 400 Bad Request
martinmac:ok.sh brightm$

Environment (please complete the following information)

  • ok.sh release: 502011c
  • curl version: curl 7.54.0 (x86_64-apple-darwin18.0) libcurl/7.54.0 LibreSSL/2.6.4 zlib/1.2.11 nghttp2/1.24.1
  • jq version: jq-1.6
  • What operating system and version.
ProductName:	Mac OS X
ProductVersion:	10.14.3
BuildVersion:	18D109
  • shell:
GNU bash, version 5.0.2(1)-release (x86_64-apple-darwin18.2.0)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Additional context

I git bisected the problem to: 502011c.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.