From 7586abc3ca2c173d5ecb78647da2cac1c0d1f0d0 Mon Sep 17 00:00:00 2001 From: knoflook Date: Mon, 1 Nov 2021 10:48:22 +0100 Subject: [PATCH] feat: add pin compatibility check --- .gitignore | 1 + tagcmp.go | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bd54331 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +fmtcoverage.html diff --git a/tagcmp.go b/tagcmp.go index 090e115..2498a56 100644 --- a/tagcmp.go +++ b/tagcmp.go @@ -187,6 +187,30 @@ func (t Tag) IsCompatible(tag Tag) bool { return true } +// IsUpgradeCompatible chekcs if upTag is compatible with a pinned version tag. +// I.e. pinning to 22-fpm should return true if upTag is 22.2.0-fpm but not 22.2.0-alpine or 23.0.0-fpm +func (pin Tag) IsUpgradeCompatible(upTag Tag) bool { + if pin.Suffix != upTag.Suffix { + return false + } + if pin.Major != upTag.Major { + return false + } + if pin.MissingMinor { + return true + } + if pin.Minor != upTag.Minor { + return false + } + if pin.MissingPatch { + return true + } + if pin.Patch != upTag.Patch { + return false + } + return true +} + // UpgradeDelta returns a TagDelta object which is the difference between an old and new tag // It can contain negative numbers if comparing with an older tag. func (curTag Tag) UpgradeDelta(newTag Tag) (TagDelta, error) {