Skip to content

Commit

Permalink
[bot] Ignore includes in docpaths
Browse files Browse the repository at this point in the history
The docpaths workflow currently blocks pull requests that rename or
delete partials, which is not intended: the docs engine does not
generate routes for partials.

This change skips redirect checking for any file path that includes the
`/includes/` segment. This follows the logic of the docs engine, which
checks whether a page path includes the `/includes/` segment and, if
not, moves it into the directory that Docusaurus uses to generate page
routes.
  • Loading branch information
ptgott committed Feb 25, 2025
1 parent 06995f2 commit d797f46
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bot/internal/bot/docpaths.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func toURLPath(p string) string {
return redir + "/"
}

// includeSegment is a file path segment that indicates the presence of
// includes, which we don't check for redirects if a PR renames or deletes them.
// Since PR filenames come from the GitHub API, paths include forward slashes.
const includeSegment = "/includes/"

// missingRedirectSources checks renamed or deleted docs pages in files to
// ensure that there is a corresponding redirect source in conf. For any missing
// redirects, it lists redirect sources that should be in conf.
Expand All @@ -112,6 +117,11 @@ func missingRedirectSources(conf []DocsRedirect, files github.PullRequestFiles)
continue
}

// Skip partials
if strings.Contains(f.Name, includeSegment) {
continue
}

switch f.Status {
case "renamed":
p := toURLPath(f.PreviousName)
Expand Down
28 changes: 28 additions & 0 deletions bot/internal/bot/docpaths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,34 @@ func TestMissingRedirectSources(t *testing.T) {
},
expected: []string{},
},
{
description: "renamed 3rd-level includes path with no redirects",
files: github.PullRequestFiles{
{
Name: "docs/pages/includes/databases/mysql-certs.mdx",
Additions: 0,
Deletions: 0,
Status: "renamed",
PreviousName: "docs/pages/includes/databases/mysql.mdx",
},
},
redirects: []DocsRedirect{},
expected: []string{},
},
{
description: "renamed 4rd-level includes path with no redirects",
files: github.PullRequestFiles{
{
Name: "docs/pages/connect-your-client/includes/mysql-certs.mdx",
Additions: 0,
Deletions: 0,
Status: "renamed",
PreviousName: "docs/pages/connect-your-client/includes/mysql.mdx",
},
},
redirects: []DocsRedirect{},
expected: []string{},
},
}

for _, c := range cases {
Expand Down

0 comments on commit d797f46

Please sign in to comment.