Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update command argocd app history to support multiple sources #17530

Merged

Conversation

Mangaal
Copy link
Contributor

@Mangaal Mangaal commented Mar 14, 2024

Description

This PR update the argocd app history command to display the history of an application grouped by their sources. The updated output now includes the source URL, along with the application history details such as ID, date, and revision.

Changes Made

  • Modified the argocd app history command to group the application history by source.
  • Included the source URL in the output for each application group.
  • Fixed an issue where the command did not display the revision for sources defined in the spec.sources array.

Previous command output

argocd app history test-3/text-book
   
ID  DATE                            REVISION
3   2024-03-08 13:04:23 +0530 IST   (2158bc9)
4   2024-03-08 13:07:40 +0530 IST  
5   2024-03-08 13:07:42 +0530 IST  
6   2024-03-08 13:09:56 +0530 IST  
7   2024-03-08 13:16:53 +0530 IST  
8   2024-03-08 13:18:31 +0530 IST  
9   2024-03-08 14:09:41 +0530 IST  
10  2024-03-08 14:09:47 +0530 IST  
11  2024-03-08 14:11:40 +0530 IST  
12  2024-03-08 14:44:14 +0530 IST

Output after changes

dist/argocd app history test-3/text-book

SOURCE  https://github.com/Mangaal/text-store.git
ID      DATE                            REVISION
3       2024-03-08 13:04:23 +0530 IST   (2158bc9)
9       2024-03-08 14:09:41 +0530 IST   (c2ceebf)
10      2024-03-08 14:09:47 +0530 IST   (c2ceebf)
11      2024-03-08 14:11:40 +0530 IST   (c2ceebf)
12      2024-03-08 14:44:14 +0530 IST   (051d4ea)

SOURCE  https://github.com/Mangaal/argocd-yaml.git
ID      DATE                            REVISION
4       2024-03-08 13:07:40 +0530 IST   (8331b14)
5       2024-03-08 13:07:42 +0530 IST   (8331b14)
6       2024-03-08 13:09:56 +0530 IST   (8331b14)
7       2024-03-08 13:16:53 +0530 IST   (8331b14)
8       2024-03-08 13:18:31 +0530 IST   (8331b14)
9       2024-03-08 14:09:41 +0530 IST   (8331b14)
10      2024-03-08 14:09:47 +0530 IST   (8331b14)
11      2024-03-08 14:11:40 +0530 IST   (8331b14)
12      2024-03-08 14:44:14 +0530 IST   (8331b14)

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • The title of the PR conforms to the Toolchain Guide
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).
  • My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.
  • Optional. My organization is added to USERS.md.
  • Optional. For bug fixes, I've indicated what older releases this fix should be cherry-picked into (this may or may not happen depending on risk/complexity).

… sources along with all the REVISIONS

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>
@Mangaal Mangaal requested a review from a team as a code owner March 14, 2024 14:56
Comment on lines 2473 to 2496
if depInfo.Source.RepoURL != "" {
rev := depInfo.Source.TargetRevision
if len(depInfo.Revision) >= 7 {
rev = fmt.Sprintf("%s (%s)", rev, depInfo.Revision[0:7])
}
varHistory[depInfo.Source.RepoURL] = append(varHistory[depInfo.Source.RepoURL], history{
id: depInfo.ID,
date: depInfo.DeployedAt.String(),
revision: rev,
})
}
if depInfo.Sources != nil {
for i, sourceInfo := range depInfo.Sources {
rev := sourceInfo.TargetRevision
if len(depInfo.Revisions) == len(depInfo.Sources) && len(depInfo.Revisions[i]) >= 7 {
rev = fmt.Sprintf("%s (%s)", rev, depInfo.Revisions[i][0:7])
}
varHistory[sourceInfo.RepoURL] = append(varHistory[sourceInfo.RepoURL], history{
id: depInfo.ID,
date: depInfo.DeployedAt.String(),
revision: rev,
})
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Sources takes priority over Source, the if clause should be something like below:

if depInfo.Sources != nil {
...
} else {
...
}

}
}

func TestPrintApplicationHistoryTableWithMultipleSources(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add a test where the application has both source and sources, but the history command only displays history of sources.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ishitasequeira , I have updated the PR with the changes you have suggested.

rev = fmt.Sprintf("%s (%s)", rev, depInfo.Revision[0:7])
if depInfo.Source.RepoURL != "" {
rev := depInfo.Source.TargetRevision
if len(depInfo.Revision) >= 7 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid this magic number 7 and create a constant like MAX_ALLOWED_REVISIONS ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @anandf , I have removed the no 7 and added a var MAX_ALLOWED_REVISIONS

Mangaal and others added 3 commits March 15, 2024 09:40
…to overlooked source if sources is persent

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>
Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>
}
}

func TestPrintApplicationHistoryTableForWhenBothSourcesAndSourceFiledsExist(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The testcase mentions source and sources field but it seems we covered it in above test case. Maybe we can remove this testcase. Rest of the PR looks good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ishitasequeira , I have removed the extra unit test.

Copy link
Member

@ishitasequeira ishitasequeira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Mangaal, the PR LGTM

@ishitasequeira ishitasequeira merged commit 38d86a9 into argoproj:master Mar 25, 2024
27 checks passed
lyda pushed a commit to lyda/argo-cd that referenced this pull request Mar 28, 2024
…rgoproj#17530)

* update argocd app history command to print app history group by thier sources along with all the REVISIONS

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>

* upadte unit test to ahve both Source and Sources and update function to overlooked source if sources is persent

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>

* remove magic no 7 and introduc a variable MAX_ALLOWED_REVISIONS

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>

* remove extra unit test

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>

* remove extra unit test TestPrintApplicationHistoryTableForWhenBothSourcesAndSourceFiledsExist()

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>

---------

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>
Co-authored-by: Ishita Sequeira <46771830+ishitasequeira@users.noreply.github.com>
Signed-off-by: Kevin Lyda <kevin@lyda.ie>
mkieweg pushed a commit to mkieweg/argo-cd that referenced this pull request Jun 11, 2024
…rgoproj#17530)

* update argocd app history command to print app history group by thier sources along with all the REVISIONS

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>

* upadte unit test to ahve both Source and Sources and update function to overlooked source if sources is persent

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>

* remove magic no 7 and introduc a variable MAX_ALLOWED_REVISIONS

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>

* remove extra unit test

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>

* remove extra unit test TestPrintApplicationHistoryTableForWhenBothSourcesAndSourceFiledsExist()

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>

---------

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>
Co-authored-by: Ishita Sequeira <46771830+ishitasequeira@users.noreply.github.com>
Hariharasuthan99 pushed a commit to AmadeusITGroup/argo-cd that referenced this pull request Jun 16, 2024
…rgoproj#17530)

* update argocd app history command to print app history group by thier sources along with all the REVISIONS

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>

* upadte unit test to ahve both Source and Sources and update function to overlooked source if sources is persent

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>

* remove magic no 7 and introduc a variable MAX_ALLOWED_REVISIONS

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>

* remove extra unit test

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>

* remove extra unit test TestPrintApplicationHistoryTableForWhenBothSourcesAndSourceFiledsExist()

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>

---------

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>
Co-authored-by: Ishita Sequeira <46771830+ishitasequeira@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants