Skip to content

add repository widget fixed-height option #624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions internal/glance/templates/repository.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@
<li>{{ .Repository.Forks | formatNumber }} forks</li>
</ul>

{{ if gt (len .Repository.Commits) 0 }}
{{ if .Repository.ShowCommits }}
<hr class="margin-block-8">
<a class="text-compact" href="https://github.com/{{ $.Repository.Name }}/commits" target="_blank" rel="noreferrer">Last {{ .CommitsLimit }} commits</a>
<div class="flex gap-7 size-h5 margin-top-3">
<ul class="list list-gap-2">
{{ range .Repository.Commits }}
<li {{ dynamicRelativeTimeAttrs .CreatedAt }}></li>
{{ end }}
{{ if .Repository.FixedHeight }}
{{ range .Repository.CommitsDiff }}
<li>&nbsp;</li>
{{ end }}
{{ end }}
</ul>
<ul class="list list-gap-2 min-width-0">
{{ range .Repository.Commits }}
Expand All @@ -24,14 +29,19 @@
</div>
{{ end }}

{{ if gt (len .Repository.PullRequests) 0 }}
{{ if .Repository.ShowPullRequests }}
<hr class="margin-block-8">
<a class="text-compact" href="https://github.com/{{ $.Repository.Name }}/pulls" target="_blank" rel="noreferrer">Open pull requests ({{ .Repository.OpenPullRequests | formatNumber }} total)</a>
<div class="flex gap-7 size-h5 margin-top-3">
<ul class="list list-gap-2">
{{ range .Repository.PullRequests }}
<li {{ dynamicRelativeTimeAttrs .CreatedAt }}></li>
{{ end }}
{{ if .Repository.FixedHeight }}
{{ range .Repository.PullRequestsDiff }}
<li>&nbsp;</li>
{{ end }}
{{ end }}
</ul>
<ul class="list list-gap-2 min-width-0">
{{ range .Repository.PullRequests }}
Expand All @@ -41,14 +51,19 @@
</div>
{{ end }}

{{ if gt (len .Repository.Issues) 0 }}
{{ if .Repository.ShowIssues }}
<hr class="margin-block-10">
<a class="text-compact" href="https://github.com/{{ $.Repository.Name }}/issues" target="_blank" rel="noreferrer">Open issues ({{ .Repository.OpenIssues | formatNumber }} total)</a>
<div class="flex gap-7 size-h5 margin-top-3">
<ul class="list list-gap-2">
{{ range .Repository.Issues }}
<li {{ dynamicRelativeTimeAttrs .CreatedAt }}></li>
{{ end }}
{{ if .Repository.FixedHeight }}
{{ range .Repository.IssuesDiff }}
<li>&nbsp;</li>
{{ end }}
{{ end }}
</ul>
<ul class="list list-gap-2 min-width-0">
{{ range .Repository.Issues }}
Expand Down
30 changes: 23 additions & 7 deletions internal/glance/widget-repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type repositoryWidget struct {
PullRequestsLimit int `yaml:"pull-requests-limit"`
IssuesLimit int `yaml:"issues-limit"`
CommitsLimit int `yaml:"commits-limit"`
FixedHeight bool `yaml:"fixed-height"`
Repository repository `yaml:"-"`
}

Expand Down Expand Up @@ -47,6 +48,7 @@ func (widget *repositoryWidget) update(ctx context.Context) {
widget.PullRequestsLimit,
widget.IssuesLimit,
widget.CommitsLimit,
widget.FixedHeight,
)

if !widget.canContinueUpdateAfterHandlingErr(err) {
Expand All @@ -70,6 +72,13 @@ type repository struct {
Issues []githubTicket
LastCommits int
Commits []githubCommitDetails
PullRequestsDiff int
IssuesDiff int
CommitsDiff int
ShowPullRequests bool
ShowIssues bool
ShowCommits bool
FixedHeight bool
}

type githubTicket struct {
Expand Down Expand Up @@ -111,7 +120,7 @@ type gitHubCommitResponseJson struct {
} `json:"commit"`
}

func fetchRepositoryDetailsFromGithub(repo string, token string, maxPRs int, maxIssues int, maxCommits int) (repository, error) {
func fetchRepositoryDetailsFromGithub(repo string, token string, maxPRs int, maxIssues int, maxCommits int, fixedHeight bool) (repository, error) {
repositoryRequest, err := http.NewRequest("GET", fmt.Sprintf("https://api.github.com/repos/%s", repo), nil)
if err != nil {
return repository{}, fmt.Errorf("%w: could not create request with repository: %v", errNoContent, err)
Expand Down Expand Up @@ -176,12 +185,19 @@ func fetchRepositoryDetailsFromGithub(repo string, token string, maxPRs int, max
}

details := repository{
Name: repositoryResponse.Name,
Stars: repositoryResponse.Stars,
Forks: repositoryResponse.Forks,
PullRequests: make([]githubTicket, 0, len(PRsResponse.Tickets)),
Issues: make([]githubTicket, 0, len(issuesResponse.Tickets)),
Commits: make([]githubCommitDetails, 0, len(commitsResponse)),
Name: repositoryResponse.Name,
Stars: repositoryResponse.Stars,
Forks: repositoryResponse.Forks,
PullRequests: make([]githubTicket, 0, len(PRsResponse.Tickets)),
Issues: make([]githubTicket, 0, len(issuesResponse.Tickets)),
Commits: make([]githubCommitDetails, 0, len(commitsResponse)),
PullRequestsDiff: maxPRs - len(PRsResponse.Tickets),
IssuesDiff: maxIssues - len(issuesResponse.Tickets),
CommitsDiff: maxCommits - len(commitsResponse),
ShowPullRequests: fixedHeight || len(PRsResponse.Tickets) > 0,
ShowIssues: fixedHeight || len(issuesResponse.Tickets) > 0,
ShowCommits: fixedHeight || len(commitsResponse) > 0,
FixedHeight: fixedHeight,
}

err = nil
Expand Down