github.com/cidverse/cid-sdk-go@v0.0.0-20240318001225-c193d83f053e/types.go (about) 1 package cidsdk 2 3 import ( 4 "strconv" 5 "time" 6 ) 7 8 // APIError defines model for Error. 9 type APIError struct { 10 Detail string `json:"detail,omitempty"` 11 Status int `json:"status,omitempty"` 12 Title string `json:"title,omitempty"` 13 } 14 15 func (e *APIError) Error() string { 16 return strconv.Itoa(e.Status) + ": " + e.Title 17 } 18 19 // Action is the common interface for all actions 20 type Action interface { 21 Execute() error 22 } 23 24 // HealthcheckResponse defines model for HealthcheckResponse. 25 type HealthcheckResponse struct { 26 Status string `json:"status"` 27 } 28 29 // ProjectDependency defines model for ProjectDependency. 30 type ProjectDependency struct { 31 Id string `json:"id,omitempty"` 32 Type string `json:"type,omitempty"` 33 Version string `json:"version,omitempty"` 34 } 35 36 // CurrentConfig defines model for CurrentConfig. 37 type CurrentConfig struct { 38 Debug bool `json:"debug,omitempty"` 39 Log map[string]string `json:"log,omitempty"` 40 ProjectDir string `json:"project_dir,omitempty"` 41 TempDir string `json:"temp_dir,omitempty"` 42 ArtifactDir string `json:"artifact_dir,omitempty"` 43 HostName string `json:"host_name,omitempty"` 44 HostUserId string `json:"host_user_id,omitempty"` 45 HostUserName string `json:"host_user_name,omitempty"` 46 HostGroupId string `json:"host_group_id,omitempty"` 47 Config string `json:"config,omitempty"` 48 } 49 50 func (c CurrentConfig) DebugFlag(id string, flag string) string { 51 if c.Debug || c.Log[id] == "debug" { 52 return flag 53 } 54 55 return "" 56 } 57 58 // ProjectModule defines model for ProjectModule. 59 type ProjectModule struct { 60 // ProjectDir project root directory 61 ProjectDir string `json:"project_dir,omitempty"` 62 63 // ModuleDir module root directory 64 ModuleDir string `json:"module_dir,omitempty"` 65 66 // Discovery module detected based on 67 Discovery []ProjectModuleDiscovery `json:"discovery,omitempty"` 68 69 // Name module name 70 Name string `json:"name,omitempty"` 71 72 // Slug module name 73 Slug string `json:"slug,omitempty"` 74 75 // BuildSystem module name 76 BuildSystem string `json:"build_system,omitempty"` 77 78 // BuildSystemSyntax module name 79 BuildSystemSyntax string `json:"build_system_syntax,omitempty"` 80 81 // Language module name 82 Language *map[string]string `json:"language,omitempty"` 83 84 // Dependencies module name 85 Dependencies *[]ProjectDependency `json:"dependencies,omitempty"` 86 87 // Files all files in the project directory 88 Files []string `json:"files,omitempty"` 89 90 // Submodules submodules 91 Submodules *[]ProjectModule `json:"submodules,omitempty"` 92 } 93 94 // ProjectModuleDiscovery contains info on the files used to discover the module 95 type ProjectModuleDiscovery struct { 96 File string `json:"file"` 97 } 98 99 type VCSCommit struct { 100 HashShort string `json:"hash_short,omitempty"` 101 Hash string `json:"hash,omitempty"` 102 Message string `json:"message,omitempty"` 103 Description string `json:"description,omitempty"` 104 Author VCSAuthor `json:"author,omitempty"` 105 Committer VCSAuthor `json:"committer,omitempty"` 106 Tags *[]VCSTag `json:"tags,omitempty"` 107 AuthoredAt time.Time `json:"authored_at,omitempty"` 108 CommittedAt time.Time `json:"committed_at,omitempty"` 109 Changes *[]VCSChange `json:"changes,omitempty"` 110 Context map[string]string `json:"context,omitempty"` 111 } 112 113 type VCSAuthor struct { 114 Name string `json:"name,omitempty"` 115 Email string `json:"email,omitempty"` 116 } 117 118 type VCSTag struct { 119 RefType string `json:"type,omitempty"` 120 Value string `json:"value,omitempty"` 121 Hash string `json:"hash,omitempty"` 122 } 123 124 type VCSRelease struct { 125 Version string `json:"version,omitempty"` 126 Ref VCSTag `json:"ref,omitempty"` 127 } 128 129 type VCSChange struct { 130 ChangeType string `json:"type,omitempty"` 131 FileFrom VCSFile `json:"file_from,omitempty"` 132 FileTo VCSFile `json:"file_to,omitempty"` 133 Patch string `json:"patch,omitempty"` 134 } 135 136 type VCSFile struct { 137 Name string `json:"name,omitempty"` 138 Size int `json:"size,omitempty"` 139 Hash string `json:"hash,omitempty"` 140 } 141 142 type VCSDiff struct { 143 FileFrom VCSFile `json:"file_from"` 144 FileTo VCSFile `json:"file_to"` 145 Lines []VCSDiffLine `json:"lines,omitempty"` 146 } 147 148 type VCSDiffLine struct { 149 Operation int `json:"operation"` 150 Content string `json:"content"` 151 } 152 153 // ActionArtifact contains information about generated artifacts 154 type ActionArtifact struct { 155 BuildID string `json:"build_id,omitempty"` 156 JobID string `json:"job_id,omitempty"` 157 ID string `json:"id,omitempty"` 158 Module string `json:"module,omitempty"` 159 Type string `json:"type,omitempty"` 160 Name string `json:"name,omitempty"` 161 Format string `json:"format,omitempty"` 162 FormatVersion string `json:"format_version,omitempty"` 163 }