-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewrite in bash and nu. nu has bonus prNum arg, documented for free
- Loading branch information
1 parent
c3d2f32
commit 1409198
Showing
2 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#! /usr/bin/env nu | ||
|
||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright Oxide Computer Company | ||
|
||
def genForCommit [commit] { | ||
let tmpDir = $"/tmp/api-diff/($commit)" | ||
rm -rf $tmpDir | ||
mkdir $tmpDir | ||
npm run --silent --prefix ../oxide.ts gen-from $commit $tmpDir | ||
npx prettier --write --log-level error $tmpDir | ||
} | ||
|
||
if (which gh | is-empty) { | ||
error make {msg: 'gh is not installed'} | ||
} | ||
|
||
def promptForPr [] { | ||
let rowTemplate = '{{range .}}{{tablerow .number .title .author.name (timeago .updatedAt)}}{{end}}' | ||
gh pr list -R oxidecomputer/omicron -L 100 --json number,title,updatedAt,author -t $rowTemplate | | ||
fzf --height 25% --reverse | | ||
cut -f1 -d ' ' | ||
} | ||
|
||
def main [prNum?: int] { | ||
let prNum = if ($prNum == null) { | ||
promptForPr | ||
} else { | ||
$prNum | ||
} | ||
|
||
let query = $"query={ | ||
repository\(owner: \"oxidecomputer\", name: \"omicron\") { | ||
pullRequest\(number: ($prNum)) { | ||
baseRefOid | ||
headRefOid | ||
} | ||
} | ||
}" | ||
|
||
let pr = (gh api graphql -f $query | from json | get data.repository.pullRequest) | ||
|
||
let base = $pr | get baseRefOid | ||
genForCommit $base | ||
|
||
let head = $pr | get headRefOid | ||
genForCommit $head | ||
|
||
# git difftool is a trick to diff with whatever you have git set to use | ||
git --no-pager difftool $"/tmp/api-diff/($base)/Api.ts" $"/tmp/api-diff/($head)/Api.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#! /usr/bin/env bash | ||
|
||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright Oxide Computer Company | ||
|
||
function genForCommit() { | ||
COMMIT=$1 | ||
TMP_DIR="/tmp/api-diff/$COMMIT" | ||
rm -rf $TMP_DIR | ||
mkdir -p $TMP_DIR | ||
npm run --silent --prefix ../oxide.ts gen-from $COMMIT $TMP_DIR | ||
npx prettier --write --log-level error $TMP_DIR | ||
} | ||
|
||
if ! command -v gh &> /dev/null; then | ||
echo "Error: gh is not installed." >&2 | ||
exit 1 | ||
fi | ||
|
||
PR_NUM=$( | ||
gh pr list -R oxidecomputer/omicron --limit 100 --json number,title,updatedAt,author \ | ||
--template '{{range .}}{{tablerow .number .title .author.name (timeago .updatedAt)}}{{end}}' | | ||
fzf --height 25% --reverse | | ||
cut -f1 -d ' ' | ||
) | ||
|
||
if ! [[ "$PR_NUM" =~ ^[0-9]+$ ]]; then | ||
echo "Error picking PR. Expected number, got $PR_NUM" >&2 | ||
exit 1 | ||
fi | ||
|
||
PR_JSON=$(gh api graphql -f query="{ | ||
repository(owner: \"oxidecomputer\", name: \"omicron\") { | ||
pullRequest(number: $PR_NUM) { | ||
baseRefOid | ||
headRefOid | ||
} | ||
} | ||
}" | jq -r '.data.repository.pullRequest') | ||
|
||
BASE=$(echo $PR_JSON | jq -r '.baseRefOid') | ||
genForCommit $BASE | ||
|
||
HEAD=$(echo $PR_JSON | jq -r '.headRefOid') | ||
genForCommit $HEAD | ||
|
||
# git difftool is a trick to diff with whatever you have git set to use | ||
git --no-pager difftool "/tmp/api-diff/$BASE/Api.ts" "/tmp/api-diff/$HEAD/Api.ts" || true |