From charlesreid1

Notes on adding a commit graph to gitea

Link to gitea repo issue: https://github.com/go-gitea/gitea/issues/6

Outstanding Issues

Two outstanding issues:

  • placement
  • data

Placement

Placement:

  • calendar should be daily commit data for a single user
  • calendar should go one of three places:
    • Behind the "Public Activity" tab on the user's profile (most appropriate place, but not very visible)
    • Just on top of the three tabs "Repositories"/"Public Activity"/"Starred repositories" on the user's profile (most visible, on user profile so useful for others to see your activity graph)
    • On the top of the user's dashboard (less useful since others cannot see your activity graph)

where are template files for top of three tabs vs public activity tab

Data

Data:

  • data model will be for calendar to ingest json served up by gitea server
  • modify gitea to cache per-user commit data (post-commit hook, daily mainenance task), provide endpoint route, provide username, it provides commit data in json form

Calculation and Caching of Data

The data is separated into a user-by-user basis

For a given user, you're asking git log for all commits by that user

(Organizations: potentially counting commits per organization)

Some things to think about:

  • when the server is spun up, that's when it will need to worry about populating that information.
  • not sure how fast the tabulation will go (particularly when interfacing directly with git)
  • worst case scenario, it could take a loooong time. in that case, we could have a timeout - draw chart; if chart data not ready, draw loading; if data doesn't show up in N seconds, gray commit graph

API Endpoint for Data

API endpoints defined in gitea/routers/routes/routes.go

Link to user routes: https://github.com/go-gitea/gitea/blob/master/routers/routes/routes.go#L179

Imagining something like git.charlesreid1.com/charlesreid1/calendarjson


Approach

The approach will be as follows:

  • Create a model in gitea/models
  • The model represents some piece of the whole grand machinery

Models: https://github.com/go-gitea/gitea/tree/master/models

  • examples: admin, wiki, branches, graph (???)

Possibly already done?: https://github.com/go-gitea/gitea/blob/master/models/graph.go


Assorted Notes

Example PR

This PR has some good topics covered: https://github.com/go-gitea/gitea/pull/3341#issuecomment-368365628

Lenny says: "If you want join, just add Join."

e.Join("INNER", "issue", "issue.id = tracked_time.issue_id").Where(opts.ToCond()).SumInt(&TrackedTime{}, "tracked_time.time")