fix(techdocs): generate correct feedback urls for GitHub

Signed-off-by: Phil Kuang <pkuang@factset.com>
This commit is contained in:
Phil Kuang
2021-08-18 13:35:54 -04:00
parent 2f291dfd04
commit 90c68a2ca8
6 changed files with 35 additions and 5 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/integration': patch
---
Export `replaceGitHubUrlType`
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-techdocs': patch
---
Fix Techdocs feedback icon link for GitHub URLs
+8
View File
@@ -434,6 +434,14 @@ export function readGoogleGcsIntegrationConfig(
config: Config,
): GoogleGcsIntegrationConfig;
// Warning: (ae-missing-release-tag) "replaceUrlType" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export function replaceGitHubUrlType(
url: string,
type: 'blob' | 'tree' | 'edit',
): string;
// Warning: (ae-missing-release-tag) "ScmIntegration" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
+4 -1
View File
@@ -25,4 +25,7 @@ export {
GithubCredentialsProvider,
} from './GithubCredentialsProvider';
export type { GithubCredentialType } from './GithubCredentialsProvider';
export { GitHubIntegration } from './GitHubIntegration';
export {
GitHubIntegration,
replaceUrlType as replaceGitHubUrlType,
} from './GitHubIntegration';
@@ -85,7 +85,7 @@ describe('addGitFeedbackLink', () => {
<html>
<article class="md-content__inner">
<h1>HeaderText</h1>
<a title="Edit this page" href="https://github.com/groupname/reponame/blob/master/docs/docname.md"></>
<a title="Edit this page" href="https://github.com/groupname/reponame/edit/master/docs/docname.md"></>
</article>
</html>
`,
@@ -99,7 +99,7 @@ describe('addGitFeedbackLink', () => {
expect(
(shadowDom.querySelector('#git-feedback-link') as HTMLLinkElement)!.href,
).toEqual(
'https://github.com/groupname/reponame/issues/new?title=Documentation%20Feedback%3A%20HeaderText&body=Page%20source%3A%0Ahttps%3A%2F%2Fgithub.com%2Fgroupname%2Freponame%2Fblob%2Fmaster%2Fdocs%2Fdocname.md%0A%0AFeedback%3A',
'https://github.com/groupname/reponame/issues/new?title=Documentation%20Feedback%3A%20HeaderText&body=Page%20source%3A%0Ahttps%3A%2F%2Fgithub.com%2Fgroupname%2Freponame%2Fedit%2Fmaster%2Fdocs%2Fdocname.md%0A%0AFeedback%3A',
);
});
@@ -15,7 +15,10 @@
*/
import type { Transformer } from './index';
import { ScmIntegrationRegistry } from '@backstage/integration';
import {
replaceGitHubUrlType,
ScmIntegrationRegistry,
} from '@backstage/integration';
import FeedbackOutlinedIcon from '@material-ui/icons/FeedbackOutlined';
import React from 'react';
import ReactDOM from 'react-dom';
@@ -51,7 +54,13 @@ export const addGitFeedbackLink = (
const issueDesc = encodeURIComponent(
`Page source:\n${sourceAnchor.href}\n\nFeedback:`,
);
const gitInfo = parseGitUrl(sourceURL.pathname);
// Convert GitHub edit url to blob type so it can be parsed by git-url-parse correctly
const gitUrl =
integration?.type === 'github'
? replaceGitHubUrlType(sourceURL.href, 'blob')
: sourceURL.href;
const gitInfo = parseGitUrl(gitUrl);
const repoPath = `/${gitInfo.organization}/${gitInfo.name}`;
const feedbackLink = sourceAnchor.cloneNode() as HTMLAnchorElement;