Skip to content

Commit 752fedf

Browse files
committed
update scripts
1 parent 489ef97 commit 752fedf

8 files changed

Lines changed: 192 additions & 7 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: PR Build
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- uses: actions/setup-node@v4
12+
with:
13+
node-version: '22.x'
14+
- run: npm ci
15+
- run: npm run build
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Update TypeScript client
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '0 15 * * 1'
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
update-client:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
- name: setup java
20+
run: |
21+
sudo apt-get install -y openjdk-21-jdk
22+
java -version
23+
- name: Update client
24+
env:
25+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
run: scripts/update_client.sh

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2025 Bitly, Inc.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Bitly API TypeScript Client
2+
3+
This package exposes a generated TypeScript client for the Bitly API.
4+
5+
## Installation
6+
7+
```sh
8+
npm install @bitly/api-client
9+
```
10+
11+
## Usage
12+
13+
```ts
14+
import { BitlinksApi, QRCodesApi } from '@bitly/api-client';
15+
16+
const bitlinksApi = new BitlinksApi({ accessToken: 'BITLY_ACCESS_TOKEN' });
17+
const link = await bitlinksApi.createBitlink({
18+
shorten: {
19+
long_url: "https://your-long-url.com/",
20+
domain: "bit.ly",
21+
// group_guid: ...
22+
}
23+
});
24+
25+
const qrcodesApi = new QRCodesApi({ accessToken: 'BITLY_ACCESS_TOKEN' })
26+
const qr = await qrcodesApi.createQRCodePublic({
27+
public_create_qr_code_request: {
28+
group_guid: "GROUP_GUID",
29+
destination: {
30+
// bitlink_idstring: link.id
31+
long_url: "https://your-long-url.com/"
32+
}
33+
}
34+
})
35+
const qrImg = await qrcodesApi.getQRCodeImagePublic({
36+
qrcode_id: qr.id,
37+
accept: 'image/png'
38+
})
39+
```
40+
41+
Refer to the official documentation for authentication requirements, available endpoints, and request/response schemas.
42+
43+
- Bitly API Docs: https://docs.bitly.com/
44+
- API Reference (v4): https://dev.bitly.com/api-reference
45+

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
},
2020
"license": "ISC",
2121
"author": "",
22-
"type": "commonjs",
22+
"type": "module",
2323
"main": "dist/index.js",
2424
"typings": "dist/index.d.ts",
2525
"scripts": {
26-
"build": "tsc"
26+
"build": "tsc",
27+
"prepare": "tsc"
2728
},
2829
"files": ["dist"],
2930
"devDependencies": {

scripts/generate_ts_api.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/sh
22
SCRIPT_PATH=$(readlink -f "$0")
33
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")
4-
VENDOR_DIR=$SCRIPT_DIR/../vendor
4+
cd $SCRIPT_DIR
5+
VENDOR_DIR=../vendor
56

67
set -e
78

@@ -12,8 +13,9 @@ if [ ! -e $VENDOR_DIR/v4.json ]; then
1213
wget https://dev.bitly.com/v4/v4.json -O $VENDOR_DIR/v4.json
1314
fi
1415

16+
rm -rf ../src
1517
./openapi-generator-cli.sh generate \
1618
--input-spec $VENDOR_DIR/v4.json \
1719
--generator-name typescript-fetch \
1820
--config ../conf/openapi_config.json \
19-
--output ../src
21+
--output ../src

scripts/update_client.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/sh
2+
SCRIPT_PATH=$(readlink -f "$0")
3+
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")
4+
cd "$SCRIPT_DIR/.." # run from repo root
5+
6+
BRANCH_NAME="client_update"
7+
BASE_BRANCH="main"
8+
COMMIT_MESSAGE="Update generated TypeScript client"
9+
PR_TITLE="feat: Update TypeScript client"
10+
PR_BODY="Automated update of generated TypeScript client."
11+
12+
DRY_RUN=false
13+
while [ "$1" != "" ]; do
14+
param=${1%%=*}
15+
value=${1#*=}
16+
case $param in
17+
--dry-run)
18+
DRY_RUN=true
19+
;;
20+
*)
21+
echo "unknown parameter \"$param\" value \"$value\""
22+
exit 1
23+
;;
24+
esac
25+
shift
26+
done
27+
28+
set -eu
29+
30+
if ! command -v gh >/dev/null 2>&1; then
31+
echo "GitHub CLI (gh) is required but not installed." >&2
32+
exit 1
33+
fi
34+
35+
if ! gh auth status >/dev/null 2>&1; then
36+
echo "authenticating with Github CLI"
37+
gh auth login
38+
fi
39+
40+
gh auth status
41+
42+
43+
echo "Configuring git user"
44+
if [ -z "$(git config --get user.name)" ]; then
45+
git config user.name "GithubActions"
46+
fi
47+
if [ -z "$(git config --get user.email)" ]; then
48+
git config user.email "github-action@automated.bit.ly"
49+
fi
50+
51+
echo "Generating TypeScript API client"
52+
./scripts/generate_ts_api.sh
53+
54+
if git diff --quiet --exit-code; then
55+
echo "No changes generated. Exiting."
56+
exit 0
57+
fi
58+
59+
echo "Creating update branch $BRANCH_NAME"
60+
git checkout -B "$BRANCH_NAME"
61+
62+
echo "Staging changes"
63+
git add -A
64+
65+
if git diff --cached --quiet --exit-code; then
66+
echo "No staged changes found after generation. Exiting."
67+
exit 0
68+
fi
69+
70+
if [ "$DRY_RUN" = "true" ]; then
71+
echo -e "DRY RYN: Changes:\n$(git status --porcelain)"
72+
exit 1
73+
fi
74+
75+
echo "Committing changes"
76+
git commit -m "$COMMIT_MESSAGE"
77+
78+
echo "Pushing branch to origin"
79+
git push --force-with-lease origin "$BRANCH_NAME"
80+
81+
82+
echo "Checking for existing pull request"
83+
OPEN_PR_COUNT=$(gh pr list --head "$BRANCH_NAME" --state open --json number --jq '. | length')
84+
if [ "$OPEN_PR_COUNT" -eq 0 ]; then
85+
echo "Creating pull request"
86+
gh pr create --head "$BRANCH_NAME" --base "$BASE_BRANCH" --title "$PR_TITLE" --body "$PR_BODY"
87+
else
88+
echo "An open pull request already exists for $BRANCH_NAME. Skipping creation."
89+
fi

tsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"compilerOptions": {
33
"declaration": true,
4-
"target": "es5",
5-
"module": "commonjs",
6-
"moduleResolution": "node",
4+
"target": "es2020",
5+
"module": "esnext",
6+
"moduleResolution": "bundler",
77
"outDir": "dist",
88
"lib": [
99
"es6",

0 commit comments

Comments
 (0)