diff options
| author | Priyansh <[email protected]> | 2025-08-26 15:31:16 +0530 |
|---|---|---|
| committer | Priyansh <[email protected]> | 2025-08-26 15:31:16 +0530 |
| commit | 2b42c3666467a26043e92982cf4fa0eb11280c70 (patch) | |
| tree | 906efabe7a477339ffda56344120afb028760691 | |
| parent | 0c66e0b7dedda5aab5a5848513ccafffdad66d6b (diff) | |
| download | eda-2b42c3666467a26043e92982cf4fa0eb11280c70.tar.xz eda-2b42c3666467a26043e92982cf4fa0eb11280c70.zip | |
| -rw-r--r-- | controllers/home.go | 13 | ||||
| -rw-r--r-- | go.mod | 5 | ||||
| -rw-r--r-- | go.sum | 14 | ||||
| -rw-r--r-- | templates/layouts/main.django | 5 | ||||
| -rw-r--r-- | templates/partials/navbar.django | 9 | ||||
| -rw-r--r-- | templates/partials/sidebar.django | 1 | ||||
| -rw-r--r-- | utils/github/github.go | 16 | ||||
| -rw-r--r-- | utils/github/types.go | 21 | ||||
| -rw-r--r-- | utils/github/user.go | 72 |
9 files changed, 154 insertions, 2 deletions
diff --git a/controllers/home.go b/controllers/home.go index 8cb7d06..5d57cdf 100644 --- a/controllers/home.go +++ b/controllers/home.go @@ -2,11 +2,22 @@ package controllers import ( "eda/config" + "eda/utils/github" "eda/utils/shortcuts" + "log" "github.com/gofiber/fiber/v2" ) func HomeController(ctx *fiber.Ctx) error { - return shortcuts.Render(ctx, config.TEMPLATE_HOME, nil) + ctx.Locals("Title", "Home") + + contributionGraph, err := github.GetContributionGraph() + if err != nil { + log.Printf("failed to get contribution graph: %v\n", err) + } + return shortcuts.Render(ctx, config.TEMPLATE_HOME, fiber.Map{ + "User": github.GetProfile(), + "ContributionCalendar": contributionGraph, + }) } @@ -5,7 +5,10 @@ go 1.24.5 require ( github.com/gofiber/fiber/v2 v2.52.9 github.com/gofiber/template/django/v3 v3.1.14 + github.com/google/go-github/v74 v74.0.0 github.com/joho/godotenv v1.5.1 + github.com/shurcooL/githubv4 v0.0.0-20240727222349-48295856cce7 + golang.org/x/oauth2 v0.30.0 ) require ( @@ -13,12 +16,14 @@ require ( github.com/flosch/pongo2/v6 v6.0.0 // indirect github.com/gofiber/template v1.8.3 // indirect github.com/gofiber/utils v1.1.0 // indirect + github.com/google/go-querystring v1.1.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/klauspost/compress v1.17.9 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect github.com/rivo/uniseg v0.2.0 // indirect + github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasthttp v1.51.0 // indirect github.com/valyala/tcplisten v1.0.0 // indirect @@ -12,6 +12,13 @@ github.com/gofiber/template/django/v3 v3.1.14 h1:SvTvs+u5vTZuu1Y2pMUD2NhaGIjBj9F github.com/gofiber/template/django/v3 v3.1.14/go.mod h1:gP4vH+T1ajZw7yaejqG1dZVdHQkMC/jPoQbmlG812I0= github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM= github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/go-github/v74 v74.0.0 h1:yZcddTUn8DPbj11GxnMrNiAnXH14gNs559AsUpNpPgM= +github.com/google/go-github/v74 v74.0.0/go.mod h1:ubn/YdyftV80VPSI26nSJvaEsTOnsjrxG3o9kJhcyak= +github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= +github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= @@ -33,6 +40,10 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/shurcooL/githubv4 v0.0.0-20240727222349-48295856cce7 h1:cYCy18SHPKRkvclm+pWm1Lk4YrREb4IOIb/YdFO0p2M= +github.com/shurcooL/githubv4 v0.0.0-20240727222349-48295856cce7/go.mod h1:zqMwyHmnN/eDOZOdiTohqIUKUrTFX62PNlu7IJdu0q8= +github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466 h1:17JxqqJY66GmZVHkmAsGEkcIu0oCe3AM420QDgGwZx0= +github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466/go.mod h1:9dIRpgIY7hVhoqfe0/FcYp0bpInZaT7dc3BYOprrIUE= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= @@ -41,10 +52,13 @@ github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1S github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g= github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= +golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI= +golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/templates/layouts/main.django b/templates/layouts/main.django index 713c42a..fa49a67 100644 --- a/templates/layouts/main.django +++ b/templates/layouts/main.django @@ -9,8 +9,11 @@ {% endblock %} </head> <body> + {% include 'partials/navbar.django' %} <main> - <aside class="sidebar"></aside> + <aside class="sidebar"> + {% include 'partials/sidebar.django' %} + </aside> <section class="content"> {% block content %} diff --git a/templates/partials/navbar.django b/templates/partials/navbar.django new file mode 100644 index 0000000..4b64efb --- /dev/null +++ b/templates/partials/navbar.django @@ -0,0 +1,9 @@ +<nav> + <div class="nav-left"> + <a href="/" class="nav-title">★彡 Eda 彡★</a> + </div> + + <div class="nav-right"> + <a href="/help">Help</a> + </div> +</nav> diff --git a/templates/partials/sidebar.django b/templates/partials/sidebar.django new file mode 100644 index 0000000..e240a66 --- /dev/null +++ b/templates/partials/sidebar.django @@ -0,0 +1 @@ +{{ User }} diff --git a/utils/github/github.go b/utils/github/github.go new file mode 100644 index 0000000..081a49a --- /dev/null +++ b/utils/github/github.go @@ -0,0 +1,16 @@ +package github + +import ( + "context" + "eda/config" + + "github.com/google/go-github/v74/github" + "github.com/shurcooL/githubv4" + "golang.org/x/oauth2" +) + +var GithubClient = github.NewClient(nil).WithAuthToken(config.GitHub.GitHubToken) + +var GraphQLClient = githubv4.NewClient(oauth2.NewClient(context.TODO(), oauth2.StaticTokenSource( + &oauth2.Token{AccessToken: config.GitHub.GitHubToken}, +))) diff --git a/utils/github/types.go b/utils/github/types.go new file mode 100644 index 0000000..8e3fe9a --- /dev/null +++ b/utils/github/types.go @@ -0,0 +1,21 @@ +package github + +type ContributionDay struct { + ContributionCount int `json:"contributionCount"` + Date string `json:"date"` + Color string `json:"color"` +} + +type ContributionWeek struct { + ContributionDays []ContributionDay `json:"contributionDays"` + FirstDay string `json:"firstDay"` +} + +type ContributionCalendar struct { + TotalContributions int `json:"totalContributions"` + Weeks []ContributionWeek `json:"weeks"` +} + +type ContributionGraph struct { + ContributionCalendar ContributionCalendar `json:"contributionCalendar"` +} diff --git a/utils/github/user.go b/utils/github/user.go new file mode 100644 index 0000000..cfd2ae3 --- /dev/null +++ b/utils/github/user.go @@ -0,0 +1,72 @@ +package github + +import ( + "context" + "eda/config" + + "github.com/google/go-github/v74/github" + "github.com/shurcooL/githubv4" +) + +func GetProfile() *github.User { + user, _, err := GithubClient.Users.Get(context.TODO(), config.GitHub.GitHubUsername) + if err != nil { + return nil + } + return user +} + +func GetContributionGraph() (*ContributionGraph, error) { + var query struct { + User struct { + ContributionsCollection struct { + ContributionCalendar struct { + TotalContributions int `graphql:"totalContributions"` + Weeks []struct { + ContributionDays []struct { + ContributionCount int `graphql:"contributionCount"` + Date string `graphql:"date"` + Color string `graphql:"color"` + } `graphql:"contributionDays"` + FirstDay string `graphql:"firstDay"` + } `graphql:"weeks"` + } `graphql:"contributionCalendar"` + } `graphql:"contributionsCollection"` + } `graphql:"user(login: $username)"` + } + + variables := map[string]interface{}{ + "username": githubv4.String(config.GitHub.GitHubUsername), + } + + err := GraphQLClient.Query(context.Background(), &query, variables) + if err != nil { + return nil, err + } + + contributionGraph := &ContributionGraph{ + ContributionCalendar: ContributionCalendar{ + TotalContributions: query.User.ContributionsCollection.ContributionCalendar.TotalContributions, + Weeks: make([]ContributionWeek, len(query.User.ContributionsCollection.ContributionCalendar.Weeks)), + }, + } + + for i, week := range query.User.ContributionsCollection.ContributionCalendar.Weeks { + contributionWeek := ContributionWeek{ + FirstDay: week.FirstDay, + ContributionDays: make([]ContributionDay, len(week.ContributionDays)), + } + + for j, day := range week.ContributionDays { + contributionWeek.ContributionDays[j] = ContributionDay{ + ContributionCount: day.ContributionCount, + Date: day.Date, + Color: day.Color, + } + } + + contributionGraph.ContributionCalendar.Weeks[i] = contributionWeek + } + + return contributionGraph, nil +} |
