Compare commits
No commits in common. "e929585371e7a3e23e8d5db8906021c7d3ad1093" and "b6acd00322f8254816b33f67de4aa7471821c36d" have entirely different histories.
e929585371
...
b6acd00322
4 changed files with 1 additions and 65 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -24,4 +24,4 @@ go.work.sum
|
||||||
|
|
||||||
# env file
|
# env file
|
||||||
.env
|
.env
|
||||||
.envrc
|
|
||||||
|
|
61
fj.go
61
fj.go
|
@ -1,61 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"net/http"
|
|
||||||
// "github.com/go-git/go-git/v5"
|
|
||||||
// "github.com/go-git/go-git/v5/storage/memory"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ForgejoRepository struct {
|
|
||||||
ID int `json:"id"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
FullName string `json:"full_name"`
|
|
||||||
HTMLURL string `json:"html_url"`
|
|
||||||
SSHURL string `json:"ssh_url"`
|
|
||||||
CloneURL string `json:"clone_url"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var API_URL = "/api/v1"
|
|
||||||
var API_USER_REPOS = "/user/repos"
|
|
||||||
|
|
||||||
func buildApiUrl(host string, token string, api string) string {
|
|
||||||
return host + API_URL + api + "?token=" + token + "&limit=1000"
|
|
||||||
}
|
|
||||||
|
|
||||||
func buildApiUrlUserRepos(host string, token string) string {
|
|
||||||
return buildApiUrl(host, token, API_USER_REPOS)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// Get the environment variables for Forgejo URL and api token
|
|
||||||
FJ_HOST := os.Getenv("FJ_HOST")
|
|
||||||
FJ_API_TOKEN := os.Getenv("FJ_API_TOKEN")
|
|
||||||
|
|
||||||
if FJ_HOST == "" || FJ_API_TOKEN == "" {
|
|
||||||
log.Fatalln("Please configure the FJ_HOST and FJ_API_TOKEN environment variables to use fj.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the master repo list from Forgejo by calling the user/repos endpoint
|
|
||||||
repos_json, err := http.Get(buildApiUrlUserRepos(FJ_HOST, FJ_API_TOKEN))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalln(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deserialize the json into a slice of Repository structs
|
|
||||||
var repos []ForgejoRepository
|
|
||||||
err = json.NewDecoder(repos_json.Body).Decode(&repos)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalln(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, repo := range repos {
|
|
||||||
log.Println(repo.Name + " " + repo.CloneURL)
|
|
||||||
}
|
|
||||||
}
|
|
3
go.mod
3
go.mod
|
@ -1,3 +0,0 @@
|
||||||
module tehga.me/forgejo/wasp/fj
|
|
||||||
|
|
||||||
go 1.23.4
|
|
0
go.sum
0
go.sum
Loading…
Add table
Reference in a new issue