-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ : compute registry details for Github https urls
- Loading branch information
Showing
3 changed files
with
55 additions
and
1 deletion.
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,14 @@ | ||
package io.gaia_app.modules; | ||
|
||
import io.gaia_app.modules.bo.TerraformModule; | ||
|
||
public interface ModuleService { | ||
|
||
/** | ||
* Updates the registry details for a module. | ||
* It tries to compute a project id from an URL, and updates the module. | ||
* @param module module to update | ||
*/ | ||
void updateRegistryDetails(TerraformModule module); | ||
|
||
} |
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,30 @@ | ||
package io.gaia_app.modules; | ||
|
||
import io.gaia_app.modules.bo.TerraformModule; | ||
import io.gaia_app.registries.RegistryDetails; | ||
import io.gaia_app.registries.RegistryType; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
@Service | ||
public class ModuleServiceImpl implements ModuleService { | ||
|
||
/** | ||
* matches https://github.com/something(.git), and captures 'something'. | ||
* The first group (.+?) expands as few times as possible. | ||
* The second non-capturing group (?:) matches the end of the line or .git | ||
*/ | ||
private static final String GITHUB_HTTPS_REPOSITORY_URL_REGEX = "https://github\\.com/(.+?)(?:$|\\.git$)"; | ||
|
||
@Override | ||
public void updateRegistryDetails(TerraformModule module) { | ||
var pattern = Pattern.compile(GITHUB_HTTPS_REPOSITORY_URL_REGEX); | ||
var matcher = pattern.matcher(module.getGitRepositoryUrl()); | ||
|
||
if (matcher.matches()) { | ||
var projectId = matcher.group(1); | ||
module.setRegistryDetails(new RegistryDetails(RegistryType.GITHUB, projectId)); | ||
} | ||
} | ||
} |
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