I am seeing weird behavior when trying to get commits older than a certain age.
self.prune_age = '1 month ago'
branchlist = self.project.branches.list(iterator=True)
print(f"\nBranches that are eligible for purging (no updates since '{self.prune_age}')")
branchlist = [branch for branch in branchlist if (branch.merged==True and branch.protected==False)]
for branch in branchlist:
commitList = self.project.commits.list(ref_name={branch.name}, since={self.prune_age}, iterator=True)
print(f"Branch {branch.name} has {len(commitList)} commits since {self.prune_age}.")
commitList = self.project.commits.list(ref_name={branch.name}, iterator=True)
for c in commitList:
print(f"Branch {branch.name} last commit: {c}")
break
Output:
Branches that are eligible for purging (no updates since ‘1 month ago’)
Branch xxx-release/2.1.0-patch-82815 has 0 commits since 1 month ago.
Branch xxx-release/2.1.0-patch-82815 last commit: <class ‘gitlab.v4.objects.commits.ProjectCommit’> => {‘id’: ‘de78a7687071dcab01fced549d28199241b026e’, ‘short_id’: ‘de78a768’, ‘created_at’: ‘2023-01-04T21:23:10.000+00:00’, ‘parent_ids’: [‘9bf4e78c13f722c1ffa06e54d49e766080780d3’], ‘title’: ‘Update .gitlab-ci.yml’, ‘message’: ‘Update .gitlab-ci.yml’, ‘author_name’: 'Some User, ‘author_email’: ‘user@email.com’, ‘authored_date’: ‘2023-01-04T21:23:10.000+00:00’, ‘committer_name’: ‘Some User’, ‘committer_email’: ‘user@email.com’, ‘committed_date’: ‘2023-01-04T21:23:10.000+00:00’, ‘trailers’: {}, ‘web_url’: ‘https://gitlab.com/xxxx/-/commit/de78a7687071dcab01fced46a9d2359241b026e’}
Obviously ‘committed_date’: ‘2023-01-04T21:23:10.000+00:00’ is less than a month ago, so why doesn’t it show up on initial query.