Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ Run the app with `sudo bugit.bugit-v2 jira`, `sudo bugit.bugit-v2 lp`, or `sudo

To uninstall, `sudo snap remove bugit`

### Jira Server Configuration

The Jira server URL can be changed after install:

```sh
sudo snap set bugit jira-server=<your_url>
```

Run `sudo snap unset bugit jira-server` to revert to the default
(`https://warthogs.atlassian.net`).

## How do I copy and paste?

This varies across different terminal emulators so I'll use gnome-terminal as the example here since it comes with ubuntu by default (and by extension ptyxis that comes with 25.10).
Expand Down
40 changes: 40 additions & 0 deletions snap/hooks/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/sh
#
# Allows the Jira server URL to be changed at runtime with:
# sudo snap set bugit jira-server=<your_url>
# Unsetting it (snap unset bugit jira-server) reverts to the default
# https://warthogs.atlassian.net, see snap/local/scripts/env_wrapper.sh
#
# Also invalidates any cached Jira credentials under /tmp when the
# server changes, since those credentials are tied to a specific server.

set -e

URL_FILE="$SNAP_DATA/jira-server-url"

OLD_JIRA_SERVER=""
if [ -f "$URL_FILE" ]; then
OLD_JIRA_SERVER="$(cat "$URL_FILE")"
fi

JIRA_SERVER="$(snapctl get jira-server)"

if [ -n "$JIRA_SERVER" ]; then
# only a lightweight sanity check: must be an http(s) URL with a host
# made up of valid URL characters (no whitespace or other invalid
# chars), not a full validation that it's a real/reachable Jira instance
if ! printf '%s' "$JIRA_SERVER" | grep -Eq '^https?://[A-Za-z0-9._~:/?#@!$&()*+,;=%-]+$'; then
echo "jira-server must be a valid URL with no whitespace or invalid characters, e.g. https://your-instance.atlassian.net (got: '$JIRA_SERVER')" >&2
exit 1
fi
echo "$JIRA_SERVER" > "$URL_FILE"
else
rm -f "$URL_FILE"
fi

# the cached basic-auth credentials (see JiraSubmitter.name in
# jira_submitter.py) belong to a specific Jira server, so drop them
# whenever the server changes to force re-authentication
if [ "$JIRA_SERVER" != "$OLD_JIRA_SERVER" ]; then
rm -f /tmp/jira_submitter-credentials.json
fi
8 changes: 6 additions & 2 deletions snap/local/scripts/env_wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ case "$SNAP_ARCH" in
;;
esac

# PERL_VERSION=$(perl -e '$^V=~/^v(\d+\.\d+)/;print $1')
# export PERL5LIB="$PERL5LIB:$SNAP/usr/lib/$ARCH/perl/$PERL_VERSION:$SNAP/usr/lib/$ARCH/perl5/$PERL_VERSION:$SNAP/usr/share/perl/$PERL_VERSION:$SNAP/usr/share/perl5"

# lets 'snap set bugit jira-server=<your_url>' override the default
# JIRA_SERVER, see snap/hooks/configure
if [ -f "$SNAP_DATA/jira-server-url" ]; then
export JIRA_SERVER="$(cat "$SNAP_DATA/jira-server-url")"
fi

# https://github.com/snapcrafters/get-iplayer/blob/candidate/snap/local/scripts/launcher
exec "$@"
5 changes: 5 additions & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ environment:
# only used for launchpad
BUGIT_APP_NAME: bugit-v2
# change this to the sandbox url for debug mode
# can be overridden after install with:
# sudo snap set bugit jira-server=<your_url>
# see snap/hooks/configure and snap/local/scripts/env_wrapper.sh
JIRA_SERVER: https://warthogs.atlassian.net
# optional, lets apt installed python apps find their libraries
PYTHONPATH: "$PYTHONPATH:$SNAP/usr/lib/python3/dist-packages"
Expand All @@ -66,6 +69,8 @@ apps:
completer: src/bugit_v2/bugit-completer.sh

submit:
command-chain:
- env_wrapper.sh
command: bin/python3 $SNAP/src/bugit_v2/apps/submit_local_archive.py

dump-standard-info:
Expand Down
8 changes: 8 additions & 0 deletions src/bugit_v2/bug_report_submitters/jira_submitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ class JiraAuthModal(ModalScreen[tuple[JiraBasicAuth, bool] | None]):
def compose(self) -> ComposeResult:
with VerticalGroup(id="top_level_container"):
yield Label(f"[b][$primary]Jira Authentication for {JIRA_SERVER_ADDRESS}")
if os.getenv("SNAP"):
# only relevant/actionable when running as a snap, so this
# is hidden for the pipx/source install where JIRA_SERVER
# is just a regular env var
yield Label(
"- Wrong server? Run "
+ "[b]sudo snap set bugit jira-server=<your_url>[/] to change it"
)
yield Input(placeholder="your.email@jira.com", id="email")
yield Input(
placeholder="A token can be created at the link below if you don't already have one",
Expand Down