Skip to content

refactor: pkg/converter#45

Merged
rokuosan merged 7 commits intomainfrom
write-tests
Mar 28, 2025
Merged

refactor: pkg/converter#45
rokuosan merged 7 commits intomainfrom
write-tests

Conversation

@rokuosan
Copy link
Copy Markdown
Owner

No description provided.

@rokuosan rokuosan self-assigned this Mar 23, 2025
@rokuosan rokuosan requested a review from Copilot March 28, 2025 15:24
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request refactors the pkg/converter package to improve its configuration handling, image URL replacement, and article export functionality while also adding comprehensive tests and updating CI configurations.

  • Refactored NewConverter to accept a configuration and token
  • Updated image URL replacement logic and front matter extraction
  • Enhanced tests for converter functions and article export, and updated CI workflows

Reviewed Changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/converter/util_test.go Added tests for the definedOr helper function
pkg/converter/util.go Introduced the generic definedOr function using reflection
pkg/converter/converter_test.go Added tests for various converter methods
pkg/converter/converter.go Refactored configuration handling, image URL replacement, and front matter extraction
pkg/converter/article_test.go Added tests for article export, directory/file creation, and date parsing
pkg/converter/article.go Updated Transform and Export methods with improved date parsing and YAML merging
cmd/generate.go Updated NewConverter usage with new configuration and token parameters
Taskfile.yml Added a test task
.github/workflows/ci-golang.yaml Updated CI to include testing alongside linting
Files not reviewed (1)
  • go.mod: Language not supported
Comments suppressed due to low confidence (2)

pkg/converter/converter.go:46

  • [nitpick] Consider revising the error message wording to be more concise (e.g., "Failed to initialize GitHub Client: token is empty") to improve clarity.
if token == "" {

pkg/converter/converter.go:229

  • [nitpick] The field name 'time' in replaceImageURLInput may be confusing due to its conflict with the standard time package. Renaming it to 'timestamp' or a similar more descriptive name can improve code clarity.
time    string

Comment thread pkg/converter/article.go
Comment on lines +165 to 186
a.Author = author.(string)
delete(extra, "author")
}
if title, ok := extra["title"]; ok {
self.Title = title.(string)
a.Title = title.(string)
delete(extra, "title")
}
if date, ok := extra["date"]; ok {
self.Date = date.(string)
a.Date = date.(string)
delete(extra, "date")
}
if categories, ok := extra["categories"]; ok {
self.Category = categories.(string)
a.Category = categories.(string)
delete(extra, "categories")
}
if tags, ok := extra["tags"]; ok {
self.Tags = tags.([]string)
a.Tags = tags.([]string)
delete(extra, "tags")
}
if draft, ok := extra["draft"]; ok {
self.Draft = draft.(bool)
a.Draft = draft.(bool)
delete(extra, "draft")
Copy link

Copilot AI Mar 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using direct type assertions (e.g., author.(string)) may cause a panic if the YAML front matter contains an unexpected type. Consider using a type switch or a safe type assertion with proper error handling.

Copilot uses AI. Check for mistakes.
@rokuosan rokuosan merged commit 1bae130 into main Mar 28, 2025
3 checks passed
@rokuosan rokuosan deleted the write-tests branch March 28, 2025 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants