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

NodeSupport: Further improve determining VCS info #8333

Closed
wants to merge 1 commit into from

Conversation

fviernau
Copy link
Member

@fviernau fviernau commented Feb 22, 2024

Adjust the fallback algorithm in various ways mainly to:

  1. Derive revisions from the URL only if they are a sha1, to avoid branch names as vcs.revision such as "master" / "main".
  2. Derive the vcs.path from the URLs
  3. Derive the vcs.type from the URLs

For our test data (see diff) this seems to be an improvement in all cases.

@fviernau fviernau requested a review from a team as a code owner February 22, 2024 14:54
@fviernau fviernau marked this pull request as draft February 22, 2024 14:55
@fviernau fviernau force-pushed the node-support-handle-textual-node branch 2 times, most recently from 22b63e7 to 5669cc1 Compare February 23, 2024 07:45
@fviernau fviernau marked this pull request as ready for review February 23, 2024 07:45
@fviernau fviernau force-pushed the node-support-handle-textual-node branch from 5669cc1 to 7c7d700 Compare February 23, 2024 07:52
@fviernau fviernau changed the title NodeSupport: Further improve parsing VCS info NodeSupport: Further improve determining VCS info Feb 23, 2024
revision = head,
path = path
revision = head.takeIf { it.isSha1() } ?: vcsInfo.revision.takeIf { it.isSha1() }.orEmpty(),
path = path.takeIf { it.isNotBlank() } ?: vcsInfo.path
Copy link
Member

Choose a reason for hiding this comment

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

I like this line, though. We can simplify to isEmpty() probably.

@fviernau
Copy link
Member Author

I've slit-out handling textal repository nodes: #8512

Improve algorithm for selecting the VCS info properties as follows:

1. Use `VcsHost.parse()` to also obtain the `type`, `revision` and
   `path` from the URL in case of a textual repository node.
2. Use only revision strings which are SHA1 sums. This avoids having
   'master' as revision. In such case using "" as revision to rely on
   the tag matching seems to be better.
3. Improve the fallback for the VCS path by deriving the path either
   from the given URL in addition to from the dedicated `directory`
   property.

Signed-off-by: Frank Viernau <[email protected]>
@fviernau fviernau force-pushed the node-support-handle-textual-node branch from 7c7d700 to a0cf897 Compare April 17, 2024 10:32
@fviernau fviernau marked this pull request as draft April 17, 2024 10:39
if (repository.isTextual) {
val url = expandNpmShortcutUrl(repository.textValue())
val vcsInfo = VcsHost.parseUrl(url)
return vcsInfo.copy(revision = head.takeIf { it.isSha1() } ?: vcsInfo.revision.takeIf { it.isSha1() }.orEmpty())
Copy link
Member

Choose a reason for hiding this comment

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

Maybe something like this instead (similar in line 171):

listOf(head, vcsInfo.revision).firstOrNull { it.isSha1() }.orEmpty()

return vcsInfo.copy(revision = head.takeIf { it.isSha1() } ?: vcsInfo.revision.takeIf { it.isSha1() }.orEmpty())
}

val type = VcsType.forName(repository["type"].textValueOrEmpty()).takeUnless { it == VcsType.UNKNOWN }
Copy link
Member

Choose a reason for hiding this comment

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

At this point, we know that repository is an object node with mandatory type and url nodes, so we could use just textValue() instead of textValueOrEmpty() here any below.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe move the .takeUnless { it == VcsType.UNKNOWN } part to line 169 to highlight why the ?: fallback is needed there?


private val SHA1_REGEX = "[0-9a-f]{7,40}".toRegex()

private fun String.isSha1(): Boolean = SHA1_REGEX.matches(this.lowercase())
Copy link
Member

Choose a reason for hiding this comment

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

Th explicit this. should be dropped here.

@fviernau
Copy link
Member Author

After looking at it again, the changes take effect in our funTest projects primarily on unprocessed VCS while processed VCS remains the same. So, I've double checked whether the changes are needed for the scans for which I've originally developed the PR for, but it turned out the scans figure out metadata successfully without this PR.

So, closing this as not needed / change unprocessed VCS only is not desired.

@fviernau fviernau closed this Apr 22, 2024
@sschuberth sschuberth deleted the node-support-handle-textual-node branch April 22, 2024 09:57
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.

3 participants