parent
ccc77a4081
commit
29620fe35a
@ -20,7 +20,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
const char* project_path = convert_relative_to_full_path(extract_value_from_arg(args, ARG_PROJECT));
|
||||
LOG_INFO("Project full path: %s", project_path);
|
||||
PlaformId project_platform_id = identify_platfrom_from_project(
|
||||
PlatformIdList* project_platforms = identify_platfroms_from_project(
|
||||
project_path,
|
||||
extract_value_from_arg(args, ARG_REMOTE));
|
||||
|
||||
|
||||
@ -1,22 +1,23 @@
|
||||
#include "base.h"
|
||||
#include "../tools/buffer.h"
|
||||
#include "../tools/log.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <regex.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <regex.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
const char* SUPPORTED_PLATFORM_NAMES [] = {
|
||||
"github.com",
|
||||
"gitlab.com"
|
||||
};
|
||||
#include "../tools/buffer.h"
|
||||
#include "../tools/alloc_wrappers.h"
|
||||
#include "../tools/log.h"
|
||||
|
||||
static void throw_regex_error(int errcode, const regex_t *preg, const char* str) {
|
||||
const char* SUPPORTED_PLATFORM_NAMES[] = {
|
||||
"github.com",
|
||||
"gitlab.com"};
|
||||
|
||||
static void throw_regex_error(int errcode, const regex_t* preg, const char* str) {
|
||||
char regex_error_buffer[REGEX_ERROR_STR_MAX_LEN] = {0};
|
||||
size_t written = regerror(errcode, preg, regex_error_buffer, REGEX_ERROR_STR_MAX_LEN);
|
||||
LOG_DEBUG("regex_error_str() errcode: %d, regerror ret: %lu", errcode, written);
|
||||
@ -35,7 +36,7 @@ static bool parse_regex_result(int value) {
|
||||
|
||||
static Lines* get_git_remote_urls_from_lines(Lines* lines, const char* remote) {
|
||||
LOG_DEBUG("Entering function %s", __func__);
|
||||
char config_remote_line_rg [GIT_CONFIG_REMOTE_STRING_MAX_LEN] = {0};
|
||||
char config_remote_line_rg[GIT_CONFIG_REMOTE_STRING_MAX_LEN] = {0};
|
||||
const int config_remote_line_written_bytes = snprintf(
|
||||
config_remote_line_rg,
|
||||
GIT_CONFIG_REMOTE_STRING_MAX_LEN,
|
||||
@ -45,11 +46,10 @@ static Lines* get_git_remote_urls_from_lines(Lines* lines, const char* remote) {
|
||||
LOG_ERROR_EXIT("Failed generating remote string [remote \"value\"]. Value %s",
|
||||
remote);
|
||||
}
|
||||
RegexWrapper regexes [GIT_CFG_RG_COUNT] = {
|
||||
RegexWrapper regexes[GIT_CFG_RG_COUNT] = {
|
||||
{.regex_pattern = config_remote_line_rg},
|
||||
{.regex_pattern = GIT_CONFIG_NEXT_SECTION_RG},
|
||||
{.regex_pattern = GIT_CONFIG_REMOTE_URL_RG}
|
||||
};
|
||||
{.regex_pattern = GIT_CONFIG_REMOTE_URL_RG}};
|
||||
for (size_t i = 0; i < GIT_CFG_RG_COUNT; i++) {
|
||||
int value = regcomp(&(regexes[i].regex_holder), regexes[i].regex_pattern, 0);
|
||||
if (value != 0) throw_regex_error(value, &(regexes[i].regex_holder), regexes[i].regex_pattern);
|
||||
@ -92,8 +92,7 @@ static Lines* get_git_remote_urls_from_lines(Lines* lines, const char* remote) {
|
||||
if (parse_regex_result(regexec(
|
||||
&(regexes[GIT_CFG_RG_USER_GIVEN_REMOTE].regex_holder),
|
||||
lines->lines[i]->data,
|
||||
0, NULL, 0))
|
||||
) {
|
||||
0, NULL, 0))) {
|
||||
remote_section_found = true;
|
||||
LOG_DEBUG("remote_section_found = true");
|
||||
continue;
|
||||
@ -107,7 +106,7 @@ static Lines* get_git_remote_urls_from_lines(Lines* lines, const char* remote) {
|
||||
return git_remote_urls;
|
||||
}
|
||||
|
||||
PlaformId identify_platfrom_from_project(const char* project_path, const char* remote) {
|
||||
PlatformIdList* identify_platfroms_from_project(const char* project_path, const char* remote) {
|
||||
LOG_DEBUG("Entering function %s", __func__);
|
||||
if (project_path == NULL) {
|
||||
LOG_ERROR_EXIT("No path supplied for project.");
|
||||
@ -119,9 +118,14 @@ PlaformId identify_platfrom_from_project(const char* project_path, const char* r
|
||||
|
||||
Lines* config_file_lines = read_file_lines(git_config_path_buffer->data);
|
||||
Lines* git_remote_urls = get_git_remote_urls_from_lines(config_file_lines, remote);
|
||||
//TODO: parse remote "origin url" to get platform
|
||||
|
||||
PlatformIdList* platforms = cdo_calloc(1, sizeof(PlatformIdList));
|
||||
platforms->size = git_remote_urls->size;
|
||||
platforms->ids = cdo_malloc(platforms->size * sizeof(PlaformId));
|
||||
// TODO: parse remote "origin url" to get platform
|
||||
|
||||
lines_free(config_file_lines);
|
||||
lines_flush(git_remote_urls);
|
||||
buffer_free(git_config_path_buffer);
|
||||
return PL_UNRECOGNIZED;
|
||||
return NULL;
|
||||
}
|
||||
@ -15,6 +15,11 @@ typedef enum PlaformId {
|
||||
PL_UNRECOGNIZED
|
||||
} PlaformId;
|
||||
|
||||
typedef struct PlatformIdList {
|
||||
PlaformId* ids;
|
||||
size_t size;
|
||||
} PlatformIdList;
|
||||
|
||||
typedef enum GitConfigRegexes {
|
||||
GIT_CFG_RG_USER_GIVEN_REMOTE,
|
||||
GIT_CFG_RG_NEXT_SECTION,
|
||||
@ -29,6 +34,6 @@ typedef struct RegexWrapper {
|
||||
|
||||
extern const char* SUPPORTED_PLATFORM_NAMES [];
|
||||
|
||||
PlaformId identify_platfrom_from_project(const char* project_path, const char* remote);
|
||||
PlatformIdList* identify_platfroms_from_project(const char* project_path, const char* remote);
|
||||
|
||||
#endif /*__PLATFORM_BASE_H__*/
|
||||
Loading…
x
Reference in New Issue
Block a user