Skip to content

Add expires field with relative time support to create-discussion, create-issue, and create-pull-request for auto-closing#5775

Merged
pelikhan merged 8 commits intomainfrom
copilot/add-expires-field-to-discussion
Dec 7, 2025
Merged

Add expires field with relative time support to create-discussion, create-issue, and create-pull-request for auto-closing#5775
pelikhan merged 8 commits intomainfrom
copilot/add-expires-field-to-discussion

Conversation

Copy link
Contributor

Copilot AI commented Dec 7, 2025

Adds support for automatically closing discussions, issues, and pull requests after a configurable expiration period. When any workflow uses the expires field, a maintenance workflow is generated to periodically check and close expired entities.

Changes

Core Implementation

  • Added expires field to CreateDiscussionsConfig, CreateIssuesConfig, and CreatePullRequestsConfig
  • Supports both integer (days) and relative time string formats:
    • Integer: expires: 7 (7 days)
    • Days: expires: 7d or 7D (7 days)
    • Weeks: expires: 2w or 2W (14 days)
    • Months: expires: 1m or 1M (30 days, approximate)
    • Years: expires: 1y or 1Y (365 days, approximate)
  • Parse expires from workflow frontmatter using shared parseExpiresFromConfig() helper
  • Pass expiration value to JavaScript via environment variables:
    • GH_AW_DISCUSSION_EXPIRES for discussions
    • GH_AW_ISSUE_EXPIRES for issues
    • GH_AW_PR_EXPIRES for pull requests (only when target-repo is not set)
  • Add XML comment <!-- gh-aw-expires: ISO8601 --> to entity body when created

Shared JavaScript Helper

  • Created expiration_helpers.cjs with reusable addExpirationComment() function
  • All three entity types use the same expiration logic for consistency

Maintenance Workflow

  • Created close_expired_discussions.cjs script:
    • Searches open discussions with expiration markers
    • Validates agentic workflow markers (> AI generated by)
    • Validates creation date before closing
    • Enforces 100 updates per run limit
    • Closes as OUTDATED with explanatory comment
  • Created maintenance_workflow.go to generate agentics-maintenance.yml when compile runs without specific workflow name
  • Maintenance runs daily at midnight UTC via cron
  • Note: Maintenance workflow currently only handles discussions; support for issues and PRs to be added

Schema & Registration

  • Updated main_workflow_schema.json for all three entity types (discussions, issues, PRs)
  • Schema accepts both integer and string with pattern ^[0-9]+[dDwWmMyY]$
  • Registered close_expired_discussions script in scripts.go
  • Integrated maintenance workflow generation into compile command

Daily Report Workflows

  • Added expires: 3d to all 8 daily report workflows that create discussions:
    • daily-code-metrics.md
    • daily-copilot-token-report.md
    • daily-firewall-report.md
    • daily-issues-report.md
    • daily-news.md
    • daily-performance-summary.md
    • daily-repo-chronicle.md
    • daily-team-status.md
  • These discussions will now automatically close after 3 days, keeping the discussion board clean

Usage

Discussions

safe-outputs:
  create-discussion:
    expires: 7    # or "7d" - Discussion expires in 7 days
    title-prefix: "[Weekly Report] "
    category: reports

Issues

safe-outputs:
  create-issue:
    expires: 1m   # or 30 - Issue expires in 30 days (1 month)
    title-prefix: "[Automated] "
    labels: ["automation"]

Pull Requests (Same-Repo Only)

safe-outputs:
  create-pull-request:
    expires: 2w   # or 14 - PR expires in 14 days (2 weeks)
    title-prefix: "[Bot] "
    # Note: expires only works when target-repo is NOT specified

Important Notes

  • Pull Request Limitation: The expires field for pull requests only works for same-repository PRs (when target-repo is not set). This ensures expiration only applies to PRs in the same repository where the workflow runs.
  • Parsing Fix: Fixed uint64 type handling - the goccy/go-yaml library returns uint64 for positive integers, which is now properly handled in all parsing functions.
  • Time Conversion: Relative time specifications are converted to days internally. Months are approximated as 30 days and years as 365 days.
Original prompt

Add a "expires" field to create-discussion that takes a relative time (in days or more) to specify when to automatically close the discussion as outdated.

add "expires" to created discussion and xml comment about expiration date.

If compile is run without workflow name AND any workflow uses the expires field, generate a "agentics-maintenance.yml" action workflow that runs daily or on workflow dispatch.

The maintenance has a "discussions" that has discussions write access and looks for expired discussions (labelled), parses the expiration date and checks if expired.

Use JavaScript stored as an embedded script compiler.

Validate that discussion has agentic workflow markers. Validate discussion creation date as well before closing issue.

Maximum updates per run is 100.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@pelikhan pelikhan marked this pull request as ready for review December 7, 2025 14:29
Copilot AI and others added 2 commits December 7, 2025 14:30
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Added Expires field to CreateDiscussionsConfig
- Updated parseDiscussionsConfig to parse expires field
- Added XML comment with expiration date to created discussions
- Created maintenance workflow generator
- Added JavaScript script for closing expired discussions
- Integrated maintenance workflow generation into compile command

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan
Copy link
Contributor

pelikhan commented Dec 7, 2025

@copilot add support for "create-issue" and issues as well. Refactor common code in separate embedded JavaScript file

@pelikhan
Copy link
Contributor

pelikhan commented Dec 7, 2025

@copilot add to "create-pull-request" (without target-repo)

Identified that expires value is being parsed from YAML but not populating the struct field. The configMap contains expires:7 but Expires field remains 0. Need to investigate type conversion issue in parseDiscussionsConfig.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add expires field to discussion creation with automatic closure Add expires field to create-discussion for auto-closing discussions Dec 7, 2025
Copilot AI requested a review from pelikhan December 7, 2025 14:53
Copilot AI and others added 2 commits December 7, 2025 15:08
Added uint64 case to switch statement. The goccy/go-yaml library returns uint64 for positive integers in YAML, which wasn't being handled by the original int/int64/float64 cases. Now successfully parses and sets the expires value.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Added Expires field to CreateIssuesConfig and CreatePullRequestsConfig structs
- Added parsing logic for expires field (uint64, int64, int, float64)
- Created shared expiration_helpers.cjs for common expiration logic
- Updated create_discussion.cjs, create_issue.cjs, and create_pull_request.cjs to use helper
- PR expires only works for same-repo PRs (when target-repo is not set)
- Added environment variables: GH_AW_ISSUE_EXPIRES and GH_AW_PR_EXPIRES

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 7, 2025

@copilot add support for "create-issue" and issues as well. Refactor common code in separate embedded JavaScript file

Added expires support to create-issue with shared expiration logic refactored into expiration_helpers.cjs. The helper function addExpirationComment() is now used by discussions, issues, and pull requests. Commit: 0ddea0f

@copilot add to "create-pull-request" (without target-repo)

Added expires support to create-pull-request, but only for same-repo PRs (when target-repo is not set). The limitation ensures expiration only applies to PRs in the same repository where the workflow runs. Commit: 0ddea0f

Copilot AI changed the title Add expires field to create-discussion for auto-closing discussions Add expires field to create-discussion, create-issue, and create-pull-request for auto-closing Dec 7, 2025
@pelikhan
Copy link
Contributor

pelikhan commented Dec 7, 2025

Also support relative time spec (7d, 1m...)

@pelikhan
Copy link
Contributor

pelikhan commented Dec 7, 2025

@copilot comment above

Copy link
Contributor

@pelikhan pelikhan left a comment

Choose a reason for hiding this comment

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

@copilot add a expires 3 days on daily report agentic workflows (that create discussions)

Added parseExpiresFromConfig helper that accepts both integer (days) and string formats:
- 7d = 7 days
- 2w = 14 days (2 weeks)
- 1m = 30 days (1 month)
- 1y = 365 days (1 year)

Updated all three entity types (discussions, issues, PRs) to use the new helper.
Updated JSON schema to accept both integer and string patterns.
Tested with various formats and confirmed correct conversion to days.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 7, 2025

@copilot comment above

Done - added relative time spec support in commit f88980e

Also support relative time spec (7d, 1m...)

Added support for relative time specifications. The expires field now accepts both integer (days) and string formats:

  • 7d or 7D = 7 days
  • 2w or 2W = 14 days (2 weeks)
  • 1m or 1M = 30 days (1 month, approximate)
  • 1y or 1Y = 365 days (1 year, approximate)

Examples:

expires: 7    # 7 days
expires: 2w   # 14 days
expires: 1m   # 30 days
expires: 1y   # 365 days

Commit: f88980e

Copilot AI changed the title Add expires field to create-discussion, create-issue, and create-pull-request for auto-closing Add expires field with relative time support to create-discussion, create-issue, and create-pull-request for auto-closing Dec 7, 2025
Copilot AI requested a review from pelikhan December 7, 2025 16:27
Added `expires: 3d` to all 8 daily report agentic workflows that create discussions:
- daily-code-metrics.md
- daily-copilot-token-report.md
- daily-firewall-report.md
- daily-issues-report.md
- daily-news.md
- daily-performance-summary.md
- daily-repo-chronicle.md
- daily-team-status.md

These discussions will now automatically expire after 3 days.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 7, 2025

@copilot add a expires 3 days on daily report agentic workflows (that create discussions)

Added expires: 3d to all 8 daily report workflows that create discussions:

  • daily-code-metrics.md
  • daily-copilot-token-report.md
  • daily-firewall-report.md
  • daily-issues-report.md
  • daily-news.md
  • daily-performance-summary.md
  • daily-repo-chronicle.md
  • daily-team-status.md

These discussions will now automatically close after 3 days. Commit: 94ba764

@pelikhan pelikhan merged commit 358baef into main Dec 7, 2025
5 checks passed
@pelikhan pelikhan deleted the copilot/add-expires-field-to-discussion branch December 7, 2025 17:47
github-actions bot added a commit that referenced this pull request Dec 8, 2025
…quest, create-discussion)

Added documentation for the new auto-expiration feature merged in PR #5775.
The expires field automatically closes issues, PRs, and discussions after
a specified time period.

Changes:
- Added expires field to create-issue section with time format examples
- Added expires field to create-pull-request section (same-repo limitation)
- Added expires field to create-discussion section
- Documented automatic agentics-maintenance.yml workflow generation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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.

2 participants