@@ -101,12 +101,12 @@ private static string ValidateTag(string tag)
101101 /// <item>Fetch all commits on the current branch using Octokit Repository.Commit.GetAll API (newest to oldest)</item>
102102 /// <item>Start collecting commits once we reach the current commit SHA</item>
103103 /// <item>Continue collecting all older commits (the history) until pagination completes</item>
104- /// <item>Fetch all tag references using Octokit Git.Reference.GetAll API with "tags" prefix </item>
104+ /// <item>Fetch all repository tags using Octokit Repository.GetAllTags API</item>
105105 /// <item>Filter tags to only those whose commit is in the branch history</item>
106- /// <item>For each valid tag, get the tag date (annotated tag date or commit date) </item>
106+ /// <item>For each valid tag, try to get annotated tag date via Git.Tag.Get, fall back to commit date if not available </item>
107107 /// <item>Sort tags by date and return as Version objects</item>
108108 /// </list>
109- /// This approach works with shallow checkouts unlike git commands and uses Git References API for reliable tag discovery .
109+ /// This approach works with shallow checkouts unlike git commands.
110110 /// </remarks>
111111 public override async Task < List < Version > > GetTagHistoryAsync ( )
112112 {
@@ -157,77 +157,49 @@ public override async Task<List<Version>> GetTagHistoryAsync()
157157 page ++ ;
158158 }
159159
160- // Get all tag references from the repository using Git References API
161- var allTagRefs = await _client . Git . Reference . GetAll ( _owner , _repo ) ;
160+ // Get all tags from the repository
161+ var allTags = await _client . Repository . GetAllTags ( _owner , _repo ) ;
162162
163- // Filter to only tag references and tags on commits in the branch history
163+ // Filter tags that are on commits in the branch history
164164 var tagsOnBranch = new List < ( Version version , DateTimeOffset date ) > ( ) ;
165165
166- foreach ( var tagRef in allTagRefs )
166+ foreach ( var tag in allTags )
167167 {
168- // Only process tag references (refs/tags/*)
169- if ( ! tagRef . Ref . StartsWith ( "refs/tags/" , StringComparison . Ordinal ) )
170- {
171- continue ;
172- }
173-
174- // Extract tag name from ref (refs/tags/v1.0.0 -> v1.0.0)
175- var tagName = tagRef . Ref . Substring ( "refs/tags/" . Length ) ;
176-
177168 // Try to parse as a version
178- var version = Version . TryCreate ( tagName ) ;
169+ var version = Version . TryCreate ( tag . Name ) ;
179170 if ( version == null )
180171 {
181172 continue ;
182173 }
183174
184- // Get the commit SHA from the tag reference
185- var commitSha = tagRef . Object . Sha ;
186-
187- // For annotated tags, we need to dereference to get the actual commit
188- if ( tagRef . Object . Type == TaggedType . Tag )
189- {
190- try
191- {
192- var tagObject = await _client . Git . Tag . Get ( _owner , _repo , tagRef . Object . Sha ) ;
193- commitSha = tagObject . Object . Sha ;
194- }
195- catch
196- {
197- // If we can't dereference, skip this tag
198- continue ;
199- }
200- }
201-
202175 // Check if this tag's commit is in the branch history
203- if ( ! branchCommits . Contains ( commitSha ) )
176+ if ( ! branchCommits . Contains ( tag . Commit . Sha ) )
204177 {
205178 continue ;
206179 }
207180
208- // Get the tag date
181+ // Get the tag date - try Git.Tag.Get first for annotated tags, fall back to commit date
209182 DateTimeOffset tagDate ;
210183 try
211184 {
212- // If this is an annotated tag, get the tagger date
213- if ( tagRef . Object . Type == TaggedType . Tag )
185+ // Try to get the annotated tag object
186+ var tagObject = await _client . Git . Tag . Get ( _owner , _repo , tag . Commit . Sha ) ;
187+ tagDate = tagObject . Tagger . Date ;
188+ }
189+ catch
190+ {
191+ // Fall back to commit date if tag object doesn't exist or doesn't have a date
192+ try
214193 {
215- var tagObject = await _client . Git . Tag . Get ( _owner , _repo , tagRef . Object . Sha ) ;
216- tagDate = tagObject . Tagger . Date ;
194+ var commit = await _client . Repository . Commit . Get ( _owner , _repo , tag . Commit . Sha ) ;
195+ tagDate = commit . Commit . Author . Date ;
217196 }
218- else
197+ catch
219198 {
220- // Lightweight tag - get commit date
221- var commit = await _client . Repository . Commit . Get ( _owner , _repo , commitSha ) ;
222- tagDate = commit . Commit . Author . Date ;
199+ // If we can't get either, skip this tag
200+ continue ;
223201 }
224202 }
225- catch
226- {
227- // Fall back to commit date if we can't get the tag object
228- var commit = await _client . Repository . Commit . Get ( _owner , _repo , commitSha ) ;
229- tagDate = commit . Commit . Author . Date ;
230- }
231203
232204 tagsOnBranch . Add ( ( version , tagDate ) ) ;
233205 }
0 commit comments