Skip to content

Commit

Permalink
Add force function for standup notes and write standup notes at due date
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Sep 27, 2023
1 parent 4155e42 commit fa8beec
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 71 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Create project CI/CD variables:
| ---- | ----- |
| GITLAB_API_TOKEN | The API access token for the user account that will create the issues (see: [GitLab docs](https://docs.gitlab.com/ce/user/profile/personal_access_tokens.html)) |
| GROUP_WIKI_ID | Optional. Set wiki for standup notes to a group wiki instead of the current project's wiki. |
| FORCE_STANDUP_NOTES_FOR_TODAY | Optional. Force the creation of standup notes for today if setting to `TRUE`. |

Finally, create a new schedule under the project CI/CD options, ensuring that
the pipeline runs at least as often as your most frequent job.
Expand Down
5 changes: 5 additions & 0 deletions gitlab_utils/gitlab_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ func GetGroupWikiId() string {
return GetEnvVariable(&envVariableParameters{Name: "GROUP_WIKI_ID", Optional: true})
}

func GetForceStandupNotesForToday() bool {
variable := GetEnvVariable(&envVariableParameters{Name: "FORCE_STANDUP_NOTES_FOR_TODAY", Optional: true})
return variable == "TRUE"
}

func GetGitClient() *gitlab.Client {
transCfg := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import (

func main() {
lastRunTime := gitlabUtils.GetLastRunTime()
forceStandupNotesForToday := gitlabUtils.GetForceStandupNotesForToday()
log.Println("Last run:", lastRunTime.Format(time.RFC3339))
log.Println("Checking whether to create recurring issues")
recurringIssues.ProcessIssueFiles(lastRunTime)
log.Println("Checking whether to adapt board labels")
boardLabels.AdaptLabels()
boardLabels.CleanLabels(lastRunTime)
log.Println("Checking whether to create standup notes")
standupNotes.WriteNotes(lastRunTime)
standupNotes.WriteNotes(lastRunTime, forceStandupNotesForToday)
log.Println("Run complete")
}
150 changes: 80 additions & 70 deletions standup_notes/standup_notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,86 +65,96 @@ func printIssue(issue *gitlab.Issue) string {
return issueString
}

func WriteNotes(lastTime time.Time) {
func CreateNotes(noteDate time.Time) {
noteName := dateUtils.GetEnDashDate(noteDate)
title := StandupTitlePrefix + noteName
if !gitlabUtils.WikiPageExists(title) {
lastNoteDate := getLastNoteDate(noteDate)
orderBy := "updated_at"
sortOrder := "desc"
issues := gitlabUtils.GetSortedProjectIssues(orderBy, sortOrder, "")
relevantIssues := []*gitlab.Issue{}
projects := []string{}
for _, issue := range issues {
if boardLabels.HasLabel(issue, constants.TestLabel) || boardLabels.HasLabel(issue, constants.RecurringLabel) {
continue
}
if issue.UpdatedAt.After(lastNoteDate) {
if issue.State != "closed" || (issue.State == "closed" && issue.ClosedAt.After(lastNoteDate)) {
relevantIssues = append(relevantIssues, issue)
projectLabels := []string{}
for _, label := range issue.Labels {
isNonProjectLabel := true
for _, nonProjectLabel := range constants.NonProjectLabels {
if label == nonProjectLabel {
isNonProjectLabel = false
break
}
}
if isNonProjectLabel {
projectLabels = append(projectLabels, label)
}
}
for _, label := range projectLabels {
labelInProjects := false
for _, project := range projects {
if label == project {
labelInProjects = true
break
}
}
if !labelInProjects {
projects = append(projects, label)
}
}
}
}
}
content := "| :rainbow: Project | :back: What I did | :soon: What I will do | :warning:️ Problems | :pencil: Notes |\n"
content += "|-------------------|-------------------|-----------------------|--------------------|----------------|\n"
sort.Strings(projects)
for _, project := range projects {
content += "| " + project + " | | | | |\n"
}
content += "\n"
content += "## Issues\n"
content += "\n"

sort.Slice(relevantIssues, func(firstIndex, secondIndex int) bool {
firstLabels := getComparableLabels(relevantIssues[firstIndex])
secondLabels := getComparableLabels(relevantIssues[secondIndex])
return firstLabels < secondLabels
})
for _, issue := range relevantIssues {
content += printIssue(issue)
}
log.Println("- Creating new wiki page", title)
gitlabUtils.CreateWikiPage(title, content)
} else {
log.Println("- Skipping creation of wiki page", title, "because it already exists")
}
}

func WriteNotes(lastTime time.Time, forceStandupNotesForToday bool) {
if (forceStandupNotesForToday) {
CreateNotes(time.Now())
}
standupIssuePath := filepath.Join(gitlabUtils.GetRecurringIssuesPath(), constants.StandupIssueTemplateName)
_, err := os.Stat(standupIssuePath)
standupIssueExists := err == nil
if !standupIssueExists {
log.Println("- Skipping creation of standup notes because no issue exists")
return
}
verbose := false
standupIssue, err := recurringIssues.GetRecurringIssue(standupIssuePath, lastTime, verbose)
if err != nil {
log.Fatal(err)
}
if standupIssue.NextTime.Before(time.Now()) {
issueDue := gitlabUtils.GetIssueDueDate(standupIssue)
issueDueString := dateUtils.GetEnDashDate(issueDue)
title := StandupTitlePrefix + issueDueString
if !gitlabUtils.WikiPageExists(title) {
lastNoteDate := getLastNoteDate(issueDue)
orderBy := "updated_at"
sortOrder := "desc"
issues := gitlabUtils.GetSortedProjectIssues(orderBy, sortOrder, "")
relevantIssues := []*gitlab.Issue{}
projects := []string{}
for _, issue := range issues {
if boardLabels.HasLabel(issue, constants.TestLabel) || boardLabels.HasLabel(issue, constants.RecurringLabel) {
continue
}
if issue.UpdatedAt.After(lastNoteDate) {
if issue.State != "closed" || (issue.State == "closed" && issue.ClosedAt.After(lastNoteDate)) {
relevantIssues = append(relevantIssues, issue)
projectLabels := []string{}
for _, label := range issue.Labels {
isNonProjectLabel := true
for _, nonProjectLabel := range constants.NonProjectLabels {
if label == nonProjectLabel {
isNonProjectLabel = false
break
}
}
if isNonProjectLabel {
projectLabels = append(projectLabels, label)
}
}
for _, label := range projectLabels {
labelInProjects := false
for _, project := range projects {
if label == project {
labelInProjects = true
break
}
}
if !labelInProjects {
projects = append(projects, label)
}
}
}
}
}
content := "| :rainbow: Project | :back: What I did | :soon: What I will do | :warning:️ Problems | :pencil: Notes |\n"
content += "|-------------------|-------------------|-----------------------|--------------------|----------------|\n"
sort.Strings(projects)
for _, project := range projects {
content += "| " + project + " | | | | |\n"
}
content += "\n"
content += "## Issues\n"
content += "\n"

sort.Slice(relevantIssues, func(firstIndex, secondIndex int) bool {
firstLabels := getComparableLabels(relevantIssues[firstIndex])
secondLabels := getComparableLabels(relevantIssues[secondIndex])
return firstLabels < secondLabels
})
for _, issue := range relevantIssues {
content += printIssue(issue)
}
log.Println("- Creating new wiki page", title)
gitlabUtils.CreateWikiPage(title, content)
} else {
log.Println("- Skipping creation of wiki page", title, "because it already exists")
}
issueDue := gitlabUtils.GetIssueDueDate(standupIssue)
if dateUtils.AreDatesEqual(issueDue, time.Now()) {
CreateNotes(issueDue)
} else {
log.Println("- Skipping creation of standup notes because it is not due yet")
}
}

0 comments on commit fa8beec

Please sign in to comment.