Skip to content
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

Handle IndexFileNames in Writer #349

Open
wants to merge 1 commit into
base: master
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
2 changes: 1 addition & 1 deletion .ci/e2e
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export GITHUB_OAUTH_TOKEN=$TOKEN
buildWebsite() {
LOCAL_BUILD=1 "${docforge_repo_path}/.ci/build" >/dev/null 2>&1
mv "$docforge_bin" /usr/local/bin/docforge
"${website_generator_path}/.ci/build"
SKIP_VALIDATION=true "${website_generator_path}/.ci/build"
}

echo "Building current docforge"
Expand Down
4 changes: 2 additions & 2 deletions .ci/integration-test
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ docforge_bin="${docforge_repo_path}/bin/docforge"

echo "Docforge version: $(${docforge_bin} version)"

GIT_OAUTH_TOKEN="github.com=${GITHUB_OAUTH_TOKEN:-$(getGitHubToken github_com)}"
GIT_OAUTH_TOKEN="${GITHUB_OAUTH_TOKEN:-$(getGitHubToken github_com)}"
test "$GIT_OAUTH_TOKEN" #fail fast

# Run docforge command with Git handler
echo "Run ${docforge_bin}"
${docforge_bin} -f "${int_test_manifest}" -d "${int_test_output_tree_dir}" --hugo --github-oauth-token-map "${GIT_OAUTH_TOKEN}" --github-info-destination ../generated-metadata
${docforge_bin} -f "${int_test_manifest}" -d "${int_test_output_tree_dir}" --hugo --github-oauth-token-map "github.com=${GIT_OAUTH_TOKEN}" --github-info-destination ../generated-metadata

#Remove untested metadata keys
removeUntestedKeysFromMetadata "${int_test_expected_metadata_dir}"
Expand Down
2 changes: 1 addition & 1 deletion cmd/app/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func configureFlags(command *cobra.Command) {
"Rewrites the relative links of documentation files to root-relative where possible.")
_ = vip.BindPFlag("hugo-base-url", command.Flags().Lookup("hugo-base-url"))

command.Flags().StringSlice("hugo-section-files", []string{"readme.md", "readme", "read.me", "index.md", "index"},
command.Flags().StringSlice("hugo-section-files", []string{"readme.md", "README.md"},
"When building a Hugo-compliant documentation bundle, files with filename matching one form this list (in that order) will be renamed to _index.md. Only useful with --hugo=true")
_ = vip.BindPFlag("hugo-section-files", command.Flags().Lookup("hugo-section-files"))

Expand Down
2 changes: 1 addition & 1 deletion pkg/workers/document/document_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (d *Worker) ProcessNode(ctx context.Context, node *manifest.Node) error {
}
cnt = bytesBuff.Bytes()
}
if err := d.writer.Write(node.Name(), node.Path, cnt, node); err != nil {
if err := d.writer.Write(node.Name(), node.Path, cnt, node, d.hugo.IndexFileNames); err != nil {
return err
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/workers/document/document_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var _ = Describe("Document resolving", func() {
}
err := dw.ProcessNode(context.TODO(), node)
Expect(err).ToNot(HaveOccurred())
name, path, cnt, nodegot := w.WriteArgsForCall(0)
name, path, cnt, nodegot, _ := w.WriteArgsForCall(0)
Expect(name).To(Equal("node"))
Expect(path).To(Equal("one"))
target, err := manifests.ReadFile("tests/expected_target.md")
Expand All @@ -91,7 +91,7 @@ var _ = Describe("Document resolving", func() {
}
err := dw.ProcessNode(context.TODO(), node)
Expect(err).ToNot(HaveOccurred())
name, path, cnt, nodegot := w.WriteArgsForCall(0)
name, path, cnt, nodegot, _ := w.WriteArgsForCall(0)
Expect(name).To(Equal("node"))
Expect(path).To(Equal("one"))
target, err := manifests.ReadFile("tests/expected_target.md")
Expand Down
2 changes: 1 addition & 1 deletion pkg/workers/githubinfo/github_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (w *Worker) WriteGithubInfo(ctx context.Context, node *manifest.Node) error
}
nodePath := node.Path
klog.V(6).Infof("writing git info for node %s/%s\n", nodePath, node.Name())
if err = w.writer.Write(node.Name(), nodePath, b.Bytes(), node); err != nil {
if err = w.writer.Write(node.Name(), nodePath, b.Bytes(), node, nil); err != nil {
return err
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/workers/githubinfo/github_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ var _ = Describe("Executing WriteGithubInfo", func() {
})
It("succeeded", func() {
Expect(err).NotTo(HaveOccurred())
_, _, content, _ := writer.WriteArgsForCall(0)
_, _, content, _, _ := writer.WriteArgsForCall(0)
Expect(string(content)).To(Equal("repoHost1 source_content\nrepoHost2 multi_source_content\n"))
})
})
Expand All @@ -116,7 +116,7 @@ var _ = Describe("Executing WriteGithubInfo", func() {

It("succeeded", func() {
Expect(err).NotTo(HaveOccurred())
name, path, content, node := writer.WriteArgsForCall(0)
name, path, content, node, _ := writer.WriteArgsForCall(0)
Expect(node).NotTo(BeNil())
Expect(node.Name()).To(Equal("README.md"))
Expect(node.Source).To(Equal("https://github.com/gardener/docforge/blob/master/README.md"))
Expand Down
2 changes: 1 addition & 1 deletion pkg/workers/resourcedownloader/resourcedownloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (d *ResourceDownloadWorker) download(ctx context.Context, Source string, Ta
if err != nil {
return err
}
if err = d.writer.Write(Target, "", blob, nil); err != nil {
if err = d.writer.Write(Target, "", blob, nil, nil); err != nil {
return err
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/workers/resourcedownloader/resourcedownloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ var _ = Describe("Executing Download", func() {
It("succeeded", func() {
Expect(err).NotTo(HaveOccurred())
Expect(writer.WriteCallCount()).To(Equal(1))
name, path, content, node := writer.WriteArgsForCall(0)
name, path, content, node, _ := writer.WriteArgsForCall(0)
Expect(node).To(BeNil())
Expect(path).To(Equal(""))
Expect(name).To(Equal("fake_target"))
Expand Down
2 changes: 1 addition & 1 deletion pkg/writers/dryRunWriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (d *dryRunWriter) GetWriter(root string) Writer {
return _w
}

func (w *writer) Write(name, path string, docBlob []byte, node *manifest.Node) error {
func (w *writer) Write(name, path string, docBlob []byte, node *manifest.Node, IndexFileNames []string) error {
if len(docBlob) > 0 && node != nil {
if !strings.HasSuffix(name, ".md") {
name = fmt.Sprintf("%s.md", name)
Expand Down
6 changes: 5 additions & 1 deletion pkg/writers/fswriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"os"
"path/filepath"
"slices"

"github.com/gardener/docforge/pkg/manifest"
"gopkg.in/yaml.v3"
Expand All @@ -21,7 +22,10 @@ type FSWriter struct {
Hugo bool
}

func (f *FSWriter) Write(name, path string, docBlob []byte, node *manifest.Node) error {
func (f *FSWriter) Write(name, path string, docBlob []byte, node *manifest.Node, IndexFileNames []string) error {
if slices.Contains(IndexFileNames, name) {
name = "_index.md"
}
//generate _index.md content
if f.Hugo && name == "_index.md" && node != nil && node.Frontmatter != nil && docBlob == nil {
buf := bytes.Buffer{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/writers/fswriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestWrite(t *testing.T) {
}
}()

err := fs.Write(tc.name, tc.path, tc.docBlob, tc.node)
err := fs.Write(tc.name, tc.path, tc.docBlob, tc.node, nil)

if err != tc.wantErr {
t.Errorf("expected err %v != %v", tc.wantErr, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/writers/writers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ import "github.com/gardener/docforge/pkg/manifest"
//
//counterfeiter:generate . Writer
type Writer interface {
Write(name, path string, resourceContent []byte, node *manifest.Node) error
Write(name, path string, resourceContent []byte, node *manifest.Node, IndexFileNames []string) error
}
23 changes: 15 additions & 8 deletions pkg/writers/writersfakes/fake_writer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.