@@ -26,7 +26,7 @@ type RevisionsData struct {
2626const annotationRevisionKey = "app.meta.revisions-metadata"
2727
2828func (asrm * AppSyncRevisionsMetadata ) GetSyncRevisionAt (idx int ) * RevisionWithMetadata {
29- if asrm == nil || asrm .SyncRevisions == nil {
29+ if asrm == nil || asrm .SyncRevisions == nil || idx < 0 || idx >= len ( asrm . SyncRevisions ) {
3030 return nil
3131 }
3232 return asrm .SyncRevisions [idx ]
@@ -60,12 +60,12 @@ func GetOperationRevision(a *appv1.Application) string {
6060 if a == nil {
6161 return ""
6262 }
63-
63+ au := & AppUtils { App : a }
6464 // this value will be used in case if application hasn't resources , like gitsource
6565 revision := a .Status .Sync .Revision
66- if a . Status . OperationState != nil && a . Status . OperationState . Operation . Sync != nil && a . Status . OperationState . Operation . Sync . Revision != "" {
66+ if au . operationStateSyncExists ( & AppRevisionFieldName ) {
6767 revision = a .Status .OperationState .Operation .Sync .Revision
68- } else if a . Operation != nil && a . Operation . Sync != nil && a . Operation . Sync . Revision != "" {
68+ } else if au . operationSyncExists ( & AppRevisionFieldName ) {
6969 revision = a .Operation .Sync .Revision
7070 }
7171
@@ -76,51 +76,55 @@ func GetOperationRevisions(a *appv1.Application) []string {
7676 if a == nil {
7777 return nil
7878 }
79+ au := & AppUtils {App : a }
7980
8081 // this value will be used in case if application hasn't resources , like gitsource
8182 revisions := a .Status .Sync .Revisions
82- if a . Status . OperationState != nil && a . Status . OperationState . Operation . Sync != nil && a . Status . OperationState . Operation . Sync . Revisions != nil && len ( a . Status . OperationState . Operation . Sync . Revisions ) > 0 {
83+ if au . operationStateSyncExists ( & AppRevisionsFieldName ) {
8384 revisions = a .Status .OperationState .Operation .Sync .Revisions
84- } else if a . Operation != nil && a . Operation . Sync != nil && a . Operation . Sync . Revisions != nil && len ( a . Operation . Sync . Revisions ) > 0 {
85+ } else if au . operationSyncExists ( & AppRevisionsFieldName ) {
8586 revisions = a .Operation .Sync .Revisions
8687 }
8788
8889 return revisions
8990}
9091
9192func GetOperationSyncResultRevision (a * appv1.Application ) * string {
92- if a == nil || a .Status .OperationState == nil || a .Status .OperationState .SyncResult == nil {
93- return nil
93+ au := & AppUtils {App : a }
94+ if au .operationSyncResultExists (nil ) {
95+ return & a .Status .OperationState .SyncResult .Revision
9496 }
9597
96- return & a . Status . OperationState . SyncResult . Revision
98+ return nil
9799}
98100
99101func GetOperationSyncResultRevisions (a * appv1.Application ) * []string {
100- if a == nil || a .Status .OperationState == nil || a .Status .OperationState .SyncResult == nil {
101- return nil
102+ au := & AppUtils {App : a }
103+ if au .operationSyncResultExists (nil ) {
104+ return & a .Status .OperationState .SyncResult .Revisions
102105 }
103106
104- return & a . Status . OperationState . SyncResult . Revisions
107+ return nil
105108}
106109
107110func GetOperationSyncRevisions (a * appv1.Application ) []string {
108111 if a == nil {
109112 return []string {}
110113 }
114+ au := & AppUtils {App : a }
111115
112116 // this value will be used in case if application hasn't resources, like empty gitsource
113117 revisions := getRevisions (RevisionsData {
114118 Revision : a .Status .Sync .Revision ,
115119 Revisions : a .Status .Sync .Revisions ,
116120 })
117121
118- if a . Status . OperationState != nil && a . Status . OperationState . Operation . Sync != nil {
122+ if au . operationStateSyncExists ( nil ) {
119123 revisions = getRevisions (RevisionsData {
120124 Revision : a .Status .OperationState .Operation .Sync .Revision ,
121125 Revisions : a .Status .OperationState .Operation .Sync .Revisions ,
122126 })
123- } else if a . Operation != nil && a . Operation . Sync != nil {
127+ } else if au . operationSyncExists ( nil ) {
124128 revisions = getRevisions (RevisionsData {
125129 Revision : a .Operation .Sync .Revision ,
126130 Revisions : a .Operation .Sync .Revisions ,
@@ -137,16 +141,17 @@ func GetOperationChangeRevisions(a *appv1.Application) []string {
137141 if a == nil {
138142 return revisions
139143 }
144+ au := & AppUtils {App : a }
140145
141146 // this value will be used in case if application hasn't resources, like empty gitsource
142- if a . Status . OperationState != nil && a . Status . OperationState . Operation . Sync != nil {
147+ if au . operationStateSyncExists ( nil ) {
143148 if a .Status .OperationState .Operation .Sync .ChangeRevision != "" || a .Status .OperationState .Operation .Sync .ChangeRevisions != nil {
144149 revisions = getRevisions (RevisionsData {
145150 Revision : a .Status .OperationState .Operation .Sync .ChangeRevision ,
146151 Revisions : a .Status .OperationState .Operation .Sync .ChangeRevisions ,
147152 })
148153 }
149- } else if a . Operation != nil && a . Operation . Sync != nil {
154+ } else if au . operationSyncExists ( nil ) {
150155 if a .Operation .Sync .ChangeRevision != "" || a .Operation .Sync .ChangeRevisions != nil {
151156 revisions = getRevisions (RevisionsData {
152157 Revision : a .Operation .Sync .ChangeRevision ,
0 commit comments