diff options
Diffstat (limited to 'Omni/Agent')
| -rw-r--r-- | Omni/Agent/Worker.hs | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/Omni/Agent/Worker.hs b/Omni/Agent/Worker.hs index f732436..3190bc7 100644 --- a/Omni/Agent/Worker.hs +++ b/Omni/Agent/Worker.hs @@ -69,7 +69,7 @@ processTask worker task = do _ <- runFormatters repo -- Try to commit (this runs git hooks which may fail) - let commitMsg = formatCommitMessage output tid + let commitMsg = formatCommitMessage task output AgentLog.updateActivity "Committing..." commitResult <- tryCommit repo commitMsg @@ -257,21 +257,15 @@ formatTask t = where formatDep dep = " - " <> TaskCore.depId dep <> " [" <> Text.pack (show (TaskCore.depType dep)) <> "]" -formatCommitMessage :: Text -> Text -> Text -formatCommitMessage ampOutput taskId = - case Text.lines (Text.strip ampOutput) of - [] -> "Task completed\n\nTask-Id: " <> taskId - [subject] -> cleanSubject subject <> "\n\nTask-Id: " <> taskId - (subject : rest) -> - let body = Text.strip (Text.unlines (dropWhile Text.null rest)) - in if Text.null body - then cleanSubject subject <> "\n\nTask-Id: " <> taskId - else cleanSubject subject <> "\n\n" <> body <> "\n\nTask-Id: " <> taskId +formatCommitMessage :: TaskCore.Task -> Text -> Text +formatCommitMessage task ampOutput = + let tid = TaskCore.taskId task + subject = cleanSubject (TaskCore.taskTitle task) + body = cleanBody ampOutput + in if Text.null body + then subject <> "\n\nTask-Id: " <> tid + else subject <> "\n\n" <> body <> "\n\nTask-Id: " <> tid where - -- Clean subject line for gitlint compliance: - -- - Remove trailing punctuation (.:!?) - -- - Truncate to 72 chars - -- - Capitalize first letter cleanSubject s = let stripped = Text.dropWhileEnd (`elem` ['.', ':', '!', '?', ' ']) s truncated = if Text.length stripped > 72 then Text.take 69 stripped <> "..." else stripped @@ -280,6 +274,13 @@ formatCommitMessage ampOutput taskId = Nothing -> truncated in capitalized + cleanBody :: Text -> Text + cleanBody output = + let stripped = Text.strip output + lns = Text.lines stripped + cleaned = map (Text.take 72) lns + in Text.intercalate "\n" cleaned + monitorLog :: FilePath -> Process.ProcessHandle -> IO () monitorLog path ph = do waitForFile path |
