1// Copyright 2022 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package app 16 17// GIT diff 18type GitDiff struct { 19 AddedLines int `json:"added_lines"` 20 DeletedLines int `json:"deleted_lines"` 21 BinaryDiff bool `json:"binary_diff"` 22} 23 24// GIT tree object (files,dirs...) 25type GitTreeObj struct { 26 Permissions string `json:"permissions"` 27 Type string `json:"type"` 28 Sha string `json:"sha"` 29 Filename string `json:"filename"` 30 BranchDiff *GitDiff `json:"branch_diff"` 31} 32 33// GitProject 34type GitProject struct { 35 RepoDir string `json:"repo_dir"` // Relative directory within repo 36 WorkDir string `json:"working_dir"` // Working directory 37 GitDir string `json:"git_dir"` // GIT directory 38 Remote string `json:"remote"` // Remote Name 39 RemoteUrl string `json:"remote_url"` // Remote URL 40 Revision string `json:"revision"` // Revision (SHA) 41 Files map[string]*GitTreeObj `json:"files"` // Files within the project 42} 43 44type GitCommitFileType int 45 46const ( 47 GitFileAdded GitCommitFileType = iota 48 GitFileModified 49 GitFileRemoved 50) 51 52type GitCommitFile struct { 53 Filename string `json:"filename"` 54 Type GitCommitFileType `json:"type"` 55} 56 57// Git commit 58type GitCommit struct { 59 Sha string `json:"sha"` 60 Files []GitCommitFile `json:"files"` 61} 62 63func (t GitCommitFileType) String() string { 64 switch t { 65 case GitFileModified: 66 return "M" 67 case GitFileAdded: 68 return "A" 69 case GitFileRemoved: 70 return "R" 71 } 72 return "" 73} 74