-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
About card edit improvements (#2950)
* Update to Edit link in Card component. * prettier * new line * Added changeset * Actually run prettier. . . * Added functionality to determine source of url for icon choice. Fixed failed tests. * Added test case for new edithref attribute * Prettier * forgot a file * correct url substring sanitation * corrected url substring sanitation * Added handling of Bitbucket Cloud and Gitlab. * Added tests for each GitLab and BitBucket edits. * Update to leverage git-url-parse * update test to reflect owner change
- Loading branch information
1 parent
f059eaf
commit 2d0bd1b
Showing
6 changed files
with
175 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@backstage/plugin-catalog': patch | ||
--- | ||
|
||
Improved the edit link to open the component yaml in edit mode in corresponding SCM. Broke out logic for createEditLink to be reused. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright 2020 Spotify AB | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { LocationSpec } from '@backstage/catalog-model'; | ||
import gitUrlParse from 'git-url-parse'; | ||
|
||
/** | ||
* Creates the edit link for components yaml file | ||
* @see LocationSpec | ||
* @param location The LocationSpec being used to determine entity SCM location | ||
* @returns string representing the edit location based on SCM path | ||
*/ | ||
|
||
export const createEditLink = (location: LocationSpec): string | undefined => { | ||
try { | ||
const urlData = gitUrlParse(location.target); | ||
const url = new URL(location.target); | ||
switch (location.type) { | ||
case 'github': | ||
case 'gitlab': | ||
return location.target.replace('/blob/', '/edit/'); | ||
case 'bitbucket': | ||
url.searchParams.set('mode', 'edit'); | ||
url.searchParams.set('spa', '0'); | ||
url.searchParams.set('at', urlData.ref); | ||
return url.toString(); | ||
case 'url': | ||
if ( | ||
urlData.source === 'github.com' || | ||
urlData.source === 'gitlab.com/' | ||
) { | ||
return location.target.replace('/blob/', '/edit/'); | ||
} else if (urlData.source === 'bitbucket.org') { | ||
url.searchParams.set('mode', 'edit'); | ||
url.searchParams.set('spa', '0'); | ||
url.searchParams.set('at', urlData.ref); | ||
return url.toString(); | ||
} | ||
return location.target; | ||
default: | ||
return location.target; | ||
} | ||
} catch { | ||
return undefined; | ||
} | ||
}; | ||
|
||
/** | ||
* Determines type based on passed in url. This is used to set the icon associated with the type of entity | ||
* @param url | ||
* @returns string representing type of icon to be used | ||
*/ | ||
export const determineUrlType = (url: string): string => { | ||
const urlData = gitUrlParse(url); | ||
|
||
if (urlData.source === 'github.com') { | ||
return 'github'; | ||
} else if (urlData.source === 'bitbucket.org') { | ||
return 'bitbucket'; | ||
} else if (urlData.source === 'gitlab.com') { | ||
return 'gitlab'; | ||
} | ||
return 'url'; | ||
}; |