Skip to content

feat: support tag events - #119

Draft
Garbee wants to merge 3 commits into
dequelabs:mainfrom
Garbee:garbee/tags
Draft

feat: support tag events#119
Garbee wants to merge 3 commits into
dequelabs:mainfrom
Garbee:garbee/tags

Conversation

@Garbee

@Garbee Garbee commented May 2, 2026

Copy link
Copy Markdown
Member

Summary

This pull request adds comprehensive support and tests for handling tag events in the getChangedFiles logic, 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

  • Added a new tag events test suite in src/git.test.ts that 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.
  • Implemented logic in src/git.ts to 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

  • Refactored getChangedFiles in src/git.ts to clearly separate logic for pull requests, tag events, and push events, delegating each to its own helper function for maintainability and readability.
  • Added utility functions such as getPushedTagName, getPreviousTagName, getPullRequestFiles, getTagFiles, and getPushFiles to modularize and clarify the codebase.

Test infrastructure improvements

  • Updated test mocks and setup in src/git.test.ts to support GraphQL queries and simulate different GitHub Actions contexts for tags, pushes, and creates.

Misc changes

  • Updated .gitignore with a generated set of ignores for various editors and all 3 main operating systems that may get developed within.

Fixes: #91

@Garbee Garbee self-assigned this May 2, 2026
@Garbee
Garbee requested a review from Copilot May 2, 2026 13:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 .gitignore to 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 thread src/git.ts
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 thread src/git.test.ts
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'
})
)
})
@Garbee

Garbee commented May 4, 2026

Copy link
Copy Markdown
Member Author

Open questions I still need to figure out with this:

  1. Mono-repos may have multiple types of tags. We should try to have a way to configure what is being looked at.
  2. Are there any ordering guarantees from the tagging API we could use to optimize the data we pull? Pulling 100 seems super excessive.

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.

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.

Support running the action on tag events

2 participants