Skip to content

Commit 89a19dc

Browse files
committed
show plausibility warnings in diff
1 parent d85996c commit 89a19dc

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

cmd/diff.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type tableRow struct {
4141
OpenProjectEntry string
4242
OpenProjectDuration string
4343
DiffInTime string
44+
Warnings string
4445
}
4546

4647
var widthOfFixedColumns = 45 // rough size of all columns that have a fixed width
@@ -119,7 +120,7 @@ var diffCmd = &cobra.Command{
119120
outputTable.SetOutputMirror(os.Stdout)
120121

121122
outputTable.AppendHeader(
122-
table.Row{"date", "tmetric entry", "tm\ndur", "OpenProject entry", "OP\ndur", "time\ndiff"},
123+
table.Row{"date", "tmetric entry", "tm\ndur", "OpenProject entry", "OP\ndur", "time\ndiff", "warnings"},
123124
)
124125
widthContentColumns := int((getTerminalWidth() - widthOfFixedColumns) / 2)
125126
outputTable.SetColumnConfigs([]table.ColumnConfig{
@@ -177,7 +178,29 @@ var diffCmd = &cobra.Command{
177178
sumDurationOpenProject += int(duration.Minutes())
178179
humanReadableDuration, _ := entry.GetHumanReadableDuration()
179180
row.OpenProjectDuration += fmt.Sprintf("%v\n\n\n\n\n\n", humanReadableDuration)
181+
workPackage, _ := openproject.GetWorkpackage(
182+
path.Base(entry.Links.WorkPackage.Href), config,
183+
)
184+
countWarnings := 0
185+
if !workPackage.Embedded.Project.Active {
186+
row.Warnings += text.Snip("- inactive project\n", widthContentColumns, "~")
187+
countWarnings++
188+
}
189+
if !workPackage.Embedded.Project.Favorited {
190+
row.Warnings += text.Snip("- not favorite project\n", widthContentColumns, "~")
191+
countWarnings++
192+
}
193+
if workPackage.Embedded.Assignee.Name != tmetricUser.Name && workPackage.Embedded.Assignee.Name != config.OpenProjectTeam {
194+
row.Warnings += text.Snip("- not my assignment\n", widthContentColumns, "~")
195+
countWarnings++
196+
}
197+
// Add the remaining newlines to make it 6 rows total
198+
for i := countWarnings; i < 6; i++ {
199+
row.Warnings += "\n"
200+
}
201+
180202
}
203+
181204
}
182205
if sumDurationTmetric > sumDurationOpenProject {
183206
diff := sumDurationTmetric - sumDurationOpenProject
@@ -188,14 +211,14 @@ var diffCmd = &cobra.Command{
188211
row.DiffInTime = strconv.Itoa(diff)
189212
totalTimeDiff += diff
190213
}
191-
192214
outputTable.AppendRow(table.Row{
193215
row.Date,
194216
strings.Trim(row.TmetricEntry, "\n"),
195217
strings.Trim(row.TmetricDuration, "\n"),
196218
strings.Trim(row.OpenProjectEntry, "\n"),
197219
strings.Trim(row.OpenProjectDuration, "\n"),
198220
row.DiffInTime,
221+
row.Warnings,
199222
})
200223
outputTable.AppendSeparator()
201224
}

0 commit comments

Comments
 (0)