Skip to content

Commit 6535879

Browse files
authored
Add feature ankitpokhrel/jira-cli (#239)
1 parent dfd535a commit 6535879

5 files changed

Lines changed: 209 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
| Feature | Description | Install method | Version |
1212
| ------- | ----------- | -------------- | ------- |
1313
| [alexpasmantier/television](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/alexpasmantier-television) | `tv` — fuzzy finder for files, text, and more | gh release | 1.0.1 |
14+
| [ankitpokhrel/jira-cli](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/ankitpokhrel-jira-cli) | `jira` — feature-rich interactive Jira command line client | gh release | 1.0.0 |
1415
| [apt-build-essential](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/apt-build-essential) | `gcc`/`g++`/`make` — C/C++ compiler toolchain via the build-essential package | apt | 1.0.0 |
1516
| [asdf-vm.com](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/asdf-vm.com) | `asdf` — multi-runtime version manager | gh release | 1.0.2 |
1617
| [astral.sh/uv](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/astral.sh-uv) | `uv`/`uvx` — fast Python package and project manager | gh release | 1.0.4 |

src/ankitpokhrel-jira-cli/NOTES.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# ankitpokhrel/jira-cli
2+
3+
## Project
4+
5+
- [jira-cli](https://github.com/ankitpokhrel/jira-cli)
6+
7+
## Description
8+
9+
Feature-rich interactive Jira command line client. `jira` lets you create, list, view, and manage Jira issues from the terminal with a TUI, and supports searching with JQL, sprints, epics, and more.
10+
11+
## Installation Method
12+
13+
Downloaded as a pre-compiled binary from the [GitHub releases page](https://github.com/ankitpokhrel/jira-cli/releases) and placed in `/usr/local/bin`.
14+
15+
## Other Notes
16+
17+
_No additional notes._
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "ankitpokhrel/jira-cli",
3+
"id": "ankitpokhrel-jira-cli",
4+
"version": "1.0.0",
5+
"description": "Install \"jira\" binary",
6+
"documentationURL": "https://github.com/devcontainer-community/devcontainer-features/tree/main/src/ankitpokhrel-jira-cli",
7+
"options": {
8+
"version": {
9+
"type": "string",
10+
"default": "latest",
11+
"proposals": [
12+
"latest"
13+
],
14+
"description": "Version of \"jira\" to install."
15+
}
16+
}
17+
}
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#!/bin/bash
2+
set -o errexit
3+
set -o pipefail
4+
set -o noclobber
5+
set -o nounset
6+
set -o allexport
7+
readonly githubRepository='ankitpokhrel/jira-cli'
8+
readonly binaryName='jira'
9+
readonly versionArgument='version'
10+
readonly binaryTargetFolder='/usr/local/bin'
11+
readonly name="${githubRepository##*/}"
12+
apt_get_update() {
13+
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
14+
echo "Running apt-get update..."
15+
apt-get update -y
16+
fi
17+
}
18+
apt_get_checkinstall() {
19+
if ! dpkg -s "$@" >/dev/null 2>&1; then
20+
apt_get_update
21+
DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends --no-install-suggests --option 'Debug::pkgProblemResolver=true' --option 'Debug::pkgAcquire::Worker=1' "$@"
22+
fi
23+
}
24+
apt_get_cleanup() {
25+
apt-get clean
26+
rm -rf /var/lib/apt/lists/*
27+
}
28+
check_curl_file_tar_installed() {
29+
declare -a requiredAptPackagesMissing=()
30+
if ! [ -r '/etc/ssl/certs/ca-certificates.crt' ]; then
31+
requiredAptPackagesMissing+=('ca-certificates')
32+
fi
33+
if ! command -v curl >/dev/null 2>&1; then
34+
requiredAptPackagesMissing+=('curl')
35+
fi
36+
if ! command -v file >/dev/null 2>&1; then
37+
requiredAptPackagesMissing+=('file')
38+
fi
39+
if ! command -v tar >/dev/null 2>&1; then
40+
requiredAptPackagesMissing+=('tar')
41+
fi
42+
declare -i requiredAptPackagesMissingCount=${#requiredAptPackagesMissing[@]}
43+
if [ $requiredAptPackagesMissingCount -gt 0 ]; then
44+
apt_get_update
45+
apt_get_checkinstall "${requiredAptPackagesMissing[@]}"
46+
apt_get_cleanup
47+
fi
48+
}
49+
curl_check_url() {
50+
local url=$1
51+
local status_code
52+
status_code=$(curl -s -o /dev/null -w '%{http_code}' "$url")
53+
if [ "$status_code" -ne 200 ] && [ "$status_code" -ne 302 ]; then
54+
echo "Failed to download '$url'. Status code: $status_code."
55+
return 1
56+
fi
57+
}
58+
curl_download_stdout() {
59+
local url=$1
60+
curl \
61+
--silent \
62+
--location \
63+
--output '-' \
64+
--connect-timeout 5 \
65+
"$url"
66+
}
67+
curl_download_untar() {
68+
local url=$1
69+
local strip=$2
70+
local target=$3
71+
local bin_path=$4
72+
curl_download_stdout "$url" | tar \
73+
-xz \
74+
-f '-' \
75+
--strip-components="$strip" \
76+
-C "$target" \
77+
"$bin_path"
78+
}
79+
debian_get_arch() {
80+
echo "$(dpkg --print-architecture)"
81+
}
82+
debian_get_target_arch() {
83+
case $(debian_get_arch) in
84+
amd64) echo 'x86_64' ;;
85+
arm64) echo 'arm64' ;;
86+
armhf) echo 'armv6' ;;
87+
i386) echo 'i386' ;;
88+
*) echo 'unknown' ;;
89+
esac
90+
}
91+
echo_banner() {
92+
local text="$1"
93+
echo -e "\e[1m\e[97m\e[41m$text\e[0m"
94+
}
95+
github_list_releases() {
96+
if [ -z "$1" ]; then
97+
echo "Usage: list_github_releases <owner/repo>"
98+
return 1
99+
fi
100+
local repo="$1"
101+
local url="https://api.github.com/repos/$repo/releases"
102+
curl -s "$url" | grep -Po '"tag_name": "\K.*?(?=")' | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | sed 's/^v//'
103+
}
104+
github_get_latest_release() {
105+
if [ -z "$1" ]; then
106+
echo "Usage: get_latest_github_release <owner/repo>"
107+
return 1
108+
fi
109+
github_list_releases "$1" | head -n 1
110+
}
111+
github_get_tag_for_version() {
112+
if [ -z "$1" ] || [ -z "$2" ]; then
113+
echo "Usage: github_get_tag_for_version <owner/repo> <version>"
114+
return 1
115+
fi
116+
local repo="$1"
117+
local ver="$2"
118+
local url="https://api.github.com/repos/$repo/releases"
119+
local escaped_version
120+
escaped_version="$(printf '%s' "$ver" | sed 's/\./\\./g')"
121+
curl -s "$url" | grep -Po '"tag_name": "\K.*?(?=")' | grep -E "^v?${escaped_version}$" | head -n 1
122+
}
123+
utils_check_version() {
124+
local version=$1
125+
if ! [[ "${version:-}" =~ ^(latest|[0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
126+
printf >&2 '=== [ERROR] Option "version" (value: "%s") is not "latest" or valid semantic version format "X.Y.Z" !\n' \
127+
"$version"
128+
exit 1
129+
fi
130+
}
131+
install() {
132+
utils_check_version "$VERSION"
133+
check_curl_file_tar_installed
134+
readonly architecture="$(debian_get_target_arch)"
135+
if [ "$VERSION" == 'latest' ] || [ -z "$VERSION" ]; then
136+
VERSION=$(github_get_latest_release "$githubRepository")
137+
fi
138+
readonly version="${VERSION:?}"
139+
readonly releaseTag="$(github_get_tag_for_version "$githubRepository" "$version")"
140+
if [ -z "$releaseTag" ]; then
141+
printf >&2 '=== [ERROR] Could not find release tag for version "%s" in "%s"!\n' "$version" "$githubRepository"
142+
exit 1
143+
fi
144+
readonly downloadUrl="https://github.com/${githubRepository}/releases/download/${releaseTag}/jira_${version}_linux_${architecture}.tar.gz"
145+
curl_check_url "$downloadUrl"
146+
readonly binaryPathInArchive="jira_${version}_linux_${architecture}/bin/${binaryName}"
147+
readonly stripComponents="$(echo -n "$binaryPathInArchive" | awk -F'/' '{print NF-1}')"
148+
readonly binaryTargetPath="${binaryTargetFolder}/${binaryName}"
149+
curl_download_untar "$downloadUrl" "$stripComponents" "$binaryTargetFolder" "$binaryPathInArchive"
150+
chmod 755 "$binaryTargetPath"
151+
apt_get_cleanup
152+
}
153+
echo_banner "devcontainer.community"
154+
echo "Installing $name..."
155+
install "$@"
156+
echo "(*) Done!"

test/ankitpokhrel-jira-cli/test.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
4+
set -e
5+
6+
# Optional: Import test library bundled with the devcontainer CLI
7+
# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib
8+
# Provides the 'check' and 'reportResults' commands.
9+
source dev-container-features-test-lib
10+
11+
# Feature-specific tests
12+
# The 'check' command comes from the dev-container-features-test-lib. Syntax is...
13+
# check <LABEL> <cmd> [args...]
14+
check "execute command" bash -c "jira version"
15+
16+
# Report results
17+
# If any of the checks above exited with a non-zero exit code, the test will fail.
18+
reportResults

0 commit comments

Comments
 (0)