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
refactor(terraform-provider): refactor manager #6637
Merged
rarkins
merged 10 commits into
renovatebot:master
from
secustor:terraform-provider-refactor
Jul 1, 2020
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0af36ae
chore(terraform-provider): replace if chain with array.some()
secustor 914ac1d
fix(terraform-provider): make git:: prefix optional
secustor 116af85
chore(terraform-provider): refactor terraform manager
secustor cba9f7c
chore(terraform-provider): replace regex matcher array lookups throug…
secustor b137c2b
fix(terraform-provider): fix coverage
secustor 3349d5b
fix(terraform-provider): renamed provider.ts to providers.ts
secustor 27d495a
fixup(terraform-provider): fix import
secustor 14f1955
fixup(terraform-provider): fix code coverage
secustor 6fffdd0
fix(terraform-provider): move git(hub) regex to module scope
secustor 8ad9e47
Merge branch 'master' into terraform-provider-refactor
rarkins File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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,75 @@ | ||
import * as datasourceGitTags from '../../datasource/git-tags'; | ||
import * as datasourceGithubTags from '../../datasource/github-tags'; | ||
import * as datasourceTerraformModule from '../../datasource/terraform-module'; | ||
import { logger } from '../../logger'; | ||
import { SkipReason } from '../../types'; | ||
import { isVersion } from '../../versioning/hashicorp'; | ||
import { PackageDependency } from '../common'; | ||
import { extractTerraformProvider } from './providers'; | ||
import { ExtractionResult, TerraformDependencyTypes } from './util'; | ||
|
||
const githubRefMatchRegex = /github.com([/:])(?<project>[^/]+\/[a-z0-9-.]+).*\?ref=(?<tag>.*)$/; | ||
const gitTagsRefMatchRegex = /(?:git::)?(?<url>(?:http|https|ssh):\/\/(?:.*@)?(?<path>.*.*\/(?<project>.*\/.*)))\?ref=(?<tag>.*)$/; | ||
|
||
export function extractTerraformModule( | ||
startingLine: number, | ||
lines: string[], | ||
moduleName: string | ||
): ExtractionResult { | ||
const result = extractTerraformProvider(startingLine, lines, moduleName); | ||
result.dependencies.forEach((dep) => { | ||
// eslint-disable-next-line no-param-reassign | ||
dep.managerData.terraformDependencyType = TerraformDependencyTypes.module; | ||
}); | ||
return result; | ||
} | ||
|
||
export function analyseTerraformModule(dep: PackageDependency): void { | ||
const githubRefMatch = githubRefMatchRegex.exec(dep.managerData.source); | ||
const gitTagsRefMatch = gitTagsRefMatchRegex.exec(dep.managerData.source); | ||
/* eslint-disable no-param-reassign */ | ||
if (githubRefMatch) { | ||
const depNameShort = githubRefMatch.groups.project.replace(/\.git$/, ''); | ||
secustor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
dep.depType = 'github'; | ||
dep.depName = 'github.com/' + depNameShort; | ||
dep.depNameShort = depNameShort; | ||
dep.currentValue = githubRefMatch.groups.tag; | ||
dep.datasource = datasourceGithubTags.id; | ||
dep.lookupName = depNameShort; | ||
if (!isVersion(dep.currentValue)) { | ||
dep.skipReason = SkipReason.UnsupportedVersion; | ||
} | ||
} else if (gitTagsRefMatch) { | ||
dep.depType = 'gitTags'; | ||
if (gitTagsRefMatch.groups.path.includes('//')) { | ||
logger.debug('Terraform module contains subdirectory'); | ||
dep.depName = gitTagsRefMatch.groups.path.split('//')[0]; | ||
dep.depNameShort = dep.depName.split(/\/(.+)/)[1]; | ||
secustor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const tempLookupName = gitTagsRefMatch.groups.url.split('//'); | ||
dep.lookupName = tempLookupName[0] + '//' + tempLookupName[1]; | ||
} else { | ||
dep.depName = gitTagsRefMatch.groups.path.replace('.git', ''); | ||
dep.depNameShort = gitTagsRefMatch.groups.project.replace('.git', ''); | ||
dep.lookupName = gitTagsRefMatch.groups.url; | ||
} | ||
dep.currentValue = gitTagsRefMatch.groups.tag; | ||
dep.datasource = datasourceGitTags.id; | ||
if (!isVersion(dep.currentValue)) { | ||
dep.skipReason = SkipReason.UnsupportedVersion; | ||
} | ||
} else if (dep.managerData.source) { | ||
const moduleParts = dep.managerData.source.split('//')[0].split('/'); | ||
if (moduleParts[0] === '..') { | ||
dep.skipReason = SkipReason.Local; | ||
} else if (moduleParts.length >= 3) { | ||
dep.depType = 'terraform'; | ||
dep.depName = moduleParts.join('/'); | ||
dep.depNameShort = dep.depName; | ||
dep.datasource = datasourceTerraformModule.id; | ||
} | ||
} else { | ||
logger.debug({ dep }, 'terraform dep has no source'); | ||
dep.skipReason = SkipReason.NoSource; | ||
} | ||
/* eslint-enable no-param-reassign */ | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need the default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a requirement of ES-lint, without it the linting fails.