feat: support tag events - #119
Draft
Garbee wants to merge 3 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the action’s getChangedFiles logic to support tag-driven workflows (push/create of tags) by diffing the current tag against a chronologically-determined previous tag, and adds a dedicated test suite to validate tag scenarios.
Changes:
- Added tag event detection and tag-to-tag diffing in
getChangedFiles, refactoring the logic into event-specific helpers. - Added GraphQL-based tag discovery (ordered by tag commit date) plus extensive tag-event test coverage.
- Expanded
.gitignoreto a comprehensive multi-editor / multi-OS ignore set.
Reviewed changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/git.ts |
Adds tag event support and refactors getChangedFiles into PR/tag/push helpers. |
src/git.test.ts |
Adds mocks for GraphQL and a new “tag events” test suite covering key cases. |
dist/index.js |
Regenerated bundled output reflecting the new tag handling/refactor. |
.gitignore |
Replaces minimal ignores with a comprehensive generated ignore list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+51
to
+75
| const result = await octokit.graphql<{ | ||
| repository: { | ||
| refs: { | ||
| nodes: Array<{ name: string }> | ||
| } | null | ||
| } | null | ||
| }>( | ||
| `query($owner: String!, $repo: String!) { | ||
| repository(owner: $owner, name: $repo) { | ||
| refs(refPrefix: "refs/tags/", first: 100, orderBy: { field: TAG_COMMIT_DATE, direction: DESC }) { | ||
| nodes { name } | ||
| } | ||
| } | ||
| }`, | ||
| { owner, repo } | ||
| ) | ||
|
|
||
| const names = result.repository?.refs?.nodes?.map((node) => node.name) ?? [] | ||
| const currentIndex = names.indexOf(currentTag) | ||
|
|
||
| if (currentIndex === -1) { | ||
| return names[0] ?? null | ||
| } | ||
|
|
||
| return names[currentIndex + 1] ?? null |
Comment on lines
+495
to
+522
| it('should fall back to most recent tag when current tag is outside the most-recent 100', async () => { | ||
| mockContext.ref = 'refs/tags/v0.0.1-old' | ||
|
|
||
| mockOctokit.graphql.mock.mockImplementation(() => | ||
| Promise.resolve({ | ||
| repository: { | ||
| refs: { | ||
| nodes: [{ name: 'v3.0.0' }, { name: 'v2.0.0' }] | ||
| } | ||
| } | ||
| }) | ||
| ) | ||
|
|
||
| mockOctokit.rest.repos.compareCommits.mock.mockImplementation(() => | ||
| Promise.resolve({ data: { files: [] } }) | ||
| ) | ||
|
|
||
| await getChangedFiles(token) | ||
|
|
||
| assert.ok( | ||
| wasCalledWith(mockOctokit.rest.repos.compareCommits, { | ||
| owner: 'test-owner', | ||
| repo: 'test-repo', | ||
| base: 'v3.0.0', | ||
| head: 'v0.0.1-old' | ||
| }) | ||
| ) | ||
| }) |
Member
Author
|
Open questions I still need to figure out with this:
I do have a concept on how to test this with E2E, but it is a huge change in itself to do that. So any E2E test with the self-test workflow will be a follow-up change. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request adds comprehensive support and tests for handling tag events in the
getChangedFileslogic, ensuring that file changes between tags are detected accurately and chronologically. It also refactors the code for clarity and separates logic for pull requests, tag events, and push events, with improved handling for edge cases and large file sets.Tag event support and testing
tag eventstest suite insrc/git.test.tsthat covers various scenarios for tag pushes and creations, including comparing new tags to previous tags, handling no previous tags, sorting tags chronologically (not lexically), and warning when too many files are changed.src/git.tsto detect tag pushes and create events, fetch previous tags using the GitHub GraphQL API (ensuring chronological order), and compare commits between tags.Refactoring and separation of concerns
getChangedFilesinsrc/git.tsto clearly separate logic for pull requests, tag events, and push events, delegating each to its own helper function for maintainability and readability.getPushedTagName,getPreviousTagName,getPullRequestFiles,getTagFiles, andgetPushFilesto modularize and clarify the codebase.Test infrastructure improvements
src/git.test.tsto support GraphQL queries and simulate different GitHub Actions contexts for tags, pushes, and creates.Misc changes
.gitignorewith a generated set of ignores for various editors and all 3 main operating systems that may get developed within.Fixes: #91