Skip to content

Commit d5eebb0

Browse files
committed
Utils enhanced with of the following:
commit 26666f0 Author: Rodrigo Motta <[email protected]> Date: Sun Mar 16 23:22:39 2025 -0300 Endpoint builder utility commit b8467c5 Author: Rodrigo Motta <[email protected]> Date: Sun Mar 16 23:19:43 2025 -0300 Update default settings commit 1f73c99 Author: Rodrigo Motta <[email protected]> Date: Sun Mar 16 23:16:51 2025 -0300 Format pull request utility commit 1346b5e Author: Rodrigo Motta <[email protected]> Date: Sun Mar 16 23:11:46 2025 -0300 Authentication utility
1 parent 7ecd282 commit d5eebb0

File tree

4 files changed

+146
-18
lines changed

4 files changed

+146
-18
lines changed

src/utils/auth.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
GITHUB_TOKEN="$(secret-tool lookup your-key your-value)"
4+
GITLAB_TOKEN="$(secret-tool lookup your-key your-value)"
5+
BITBUCKET_USER="$(secret-tool lookup your-key your-value)"
6+
BITBUCKET_APPWD="$(secret-tool lookup your-key your-value)"
7+
# Construct basic authentication header
8+
BITBUCKET_AUTH="Authorization: Basic $(echo -n "$BITBUCKET_USER:$BITBUCKET_APPWD" | base64)"

src/utils/endpoints.sh

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/usr/bin/env bash
2+
3+
# API base URL
4+
BB_URL="https://api.bitbucket.org/2.0"
5+
GH_URL="https://api.github.com"
6+
GL_URL="https://gitlab.com/api/v4"
7+
8+
# API Repo Endpoints
9+
BB_REPO_EP="repositories"
10+
GH_REPO_EP="repos"
11+
GL_REPO_EP="projects"
12+
13+
14+
# Bitbucket endpoint builder
15+
function build_bb_endpoint() {
16+
local route
17+
local owner
18+
local repo
19+
20+
route="$1"
21+
owner="$2" # Workspace and Project key
22+
repo="$3"
23+
24+
if [[ -z "$route" || -z "$owner" || -z "$repo" ]]; then
25+
echo "Error: route, owner, and repository are required for Bitbucket."
26+
exit 1
27+
fi
28+
29+
# Endpoint selector
30+
case "$route" in
31+
PR)
32+
# Using $owner as workspace
33+
endpoint="$BB_URL/$BB_REPO_EP/$owner/$repo/pullrequests"
34+
;;
35+
REPOS)
36+
endpoint="$BB_URL/$BB_REPO_EP/$owner/$repo"
37+
;;
38+
# ... adicionar outras rotas específicas do Bitbucket
39+
*)
40+
echo "Choice route."
41+
;;
42+
esac
43+
44+
echo "$endpoint"
45+
}
46+
47+
48+
# GitHub endpoint builder
49+
function build_gh_endpoint() {
50+
local route
51+
local owner
52+
local repo
53+
54+
route="$1"
55+
owner="$2"
56+
repo="$3"
57+
58+
if [[ -z "$route" || -z "$owner" || -z "$repo" ]]; then
59+
echo "Error: route, owner, and repository are required for GitHub."
60+
exit 1
61+
fi
62+
63+
# Endpoint selector
64+
case "$route" in
65+
PR)
66+
endpoint="$GH_URL/$GH_REPO_EP/$owner/$repo/pulls"
67+
;;
68+
REPOS)
69+
endpoint="$GH_URL/$GH_REPO_EP/$owner/$repo"
70+
;;
71+
# ... adicionar outras rotas específicas do GitHub
72+
*)
73+
echo "Choice route."
74+
;;
75+
esac
76+
77+
echo "$endpoint"
78+
}
79+
80+
81+
# GitLab endpoint builder
82+
function build_gl_endpoint() {
83+
local route
84+
local owner
85+
local repo
86+
local SLASH_ENCODED
87+
88+
route="$1"
89+
owner="$2"
90+
repo="$3"
91+
SLASH_ENCODED="%2F"
92+
93+
if [[ -z "$route" || -z "$owner" || -z "$repo" ]]; then
94+
echo "Error: route, owner, and repository are required for Gitlab."
95+
exit 1
96+
fi
97+
98+
# Endpoint selector
99+
case "$route" in
100+
PR)
101+
endpoint="$GL_URL/$GL_REPO_EP/$owner$SLASH_ENCODED$repo/merge_requests"
102+
;;
103+
REPOS)
104+
endpoint="$GL_URL/$GL_REPO_EP/$owner$SLASH_ENCODED$repo"
105+
;;
106+
# ... adicionar outras rotas específicas do Gitlab
107+
*)
108+
echo "Choice route."
109+
;;
110+
esac
111+
112+
echo "$endpoint"
113+
}

src/utils/format_pullrequest.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
4+
function format_pullrequest() {
5+
local content
6+
local section="$1" # Título ou corpo
7+
local file="pr" # Nome do arquivo
8+
9+
# Lê o arquivo
10+
content=$(cat "$file")
11+
12+
# Extrai a seção desejada
13+
if [[ "$section" == "title" ]]; then
14+
content=$(head -n 1 "$file")
15+
else
16+
content=$(tail -n +2 "$file")
17+
fi
18+
19+
# Escapa aspas duplas e quebras de linha
20+
escaped_content=$(echo "$content" | sed "s/'/\\'/g; s/$/\\\n/g; s/\n//g;" | tr -d '\n')
21+
22+
# Retorna o conteúdo formatado
23+
echo "$escaped_content"
24+
25+
}

src/utils/settings.sh

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
#!/usr/bin/env bash
22

3-
GITHUB_TOKEN="$(secret-tool lookup your-key your-value)"
4-
GITLAB_TOKEN="$(secret-tool lookup your-key your-value)"
5-
BITBUCKET_USER="$(secret-tool lookup your-key your-value)"
6-
BITBUCKET_APPWD="$(secret-tool lookup your-key your-value)"
7-
# Construct basic authentication header
8-
BITBUCKET_AUTH="Authorization: Basic $(echo -n "$BITBUCKET_USER:$BITBUCKET_APPWD" | base64)"
9-
10-
113
# Default parameters
124
DEF_GH_OWNER="you-gthub-user"
135
DEF_GL_OWNER="you-gitlab-user"
@@ -18,13 +10,3 @@ DEF_PROJECT="your-project"
1810
DEFAULT_BRANCH="main"
1911
CURRENT_BRANCH="$(git branch --show-current)"
2012

21-
22-
# API base URL
23-
BB_API="https://api.bitbucket.org/2.0"
24-
GH_API="https://api.github.com"
25-
GL_API="https://gitlab.com/api/v4"
26-
27-
# API Repo Endpoints
28-
BB_REPO_EP="repositories"
29-
GH_REPO_EP="repos"
30-
GL_REPO_EP="projects"

0 commit comments

Comments
 (0)