Refactor action to use composite run steps and support cross-repository issue creation

- Changed action execution from Docker to composite with Python setup.
- Added `TARGET_REPO` input to allow issue creation in a specified repository.
- Updated `GitHubClient` to use `TARGET_REPO` for issue and milestone URLs.
- Enhanced README with instructions for cross-repository usage.
- Introduced example workflow for creating TODO issues in another repository.

Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com>
This commit is contained in:
Shakar Bakr 2025-05-15 15:49:54 +03:00
parent 3bd536e14a
commit 1b4753ffdd
No known key found for this signature in database
GPG Key ID: DA55A26823AE3C28
4 changed files with 104 additions and 14 deletions

View File

@ -0,0 +1,34 @@
name: Create TODO Issues in Another Repository
# NOTE: This is an example for when the TARGET_REPO feature is released.
# The current published version of the action does not yet have this feature.
on:
push:
branches: [main, master]
permissions:
contents: read
issues: write
jobs:
todo-to-issue:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Required to get the diff between commits
- name: TODO to Issue
# Use the local version of the action (after you've made the changes)
uses: ./
with:
TARGET_REPO: "my-org/target-repo" # Replace with your target repository
TOKEN: ${{ secrets.CROSS_REPO_TOKEN }} # Token with access to the target repository
CLOSE_ISSUES: "true" # Optional: close issues when TODOs are removed
AUTO_ASSIGN: "true" # Optional: assign issues to the committer
# Other optional configurations:
# IDENTIFIERS: '{"TODO": "TODO:", "FIXME": "Fix needed:"}' # Custom identifiers for TODOs
# LABELS: 'todo,fixme' # Default labels to apply to all created issues

View File

@ -17,13 +17,14 @@ class GitHubClient(Client):
self.base_url = f'{self.github_url}/'
self.repos_url = f'{self.base_url}repos/'
self.repo = os.getenv('INPUT_REPO')
self.target_repo = os.getenv('INPUT_TARGET_REPO', self.repo) # Default to current repo if not specified
self.before = os.getenv('INPUT_BEFORE')
self.sha = os.getenv('INPUT_SHA')
self.commits = json.loads(os.getenv('INPUT_COMMITS')) or []
self.__init_diff_url__()
self.token = os.getenv('INPUT_TOKEN')
self.issues_url = f'{self.repos_url}{self.repo}/issues'
self.milestones_url = f'{self.repos_url}{self.repo}/milestones'
self.issues_url = f'{self.repos_url}{self.target_repo}/issues'
self.milestones_url = f'{self.repos_url}{self.target_repo}/milestones'
self.issue_headers = {
'Content-Type': 'application/json',
'Authorization': f'token {self.token}',
@ -394,4 +395,5 @@ class GitHubClient(Client):
return pr_request.status_code
def get_issue_url(self, new_issue_number):
return f'{self.line_base_url}{self.repo}/issues/{new_issue_number}'
"""Get the URL for the issue."""
return f'{self.line_base_url}{self.target_repo}/issues/{new_issue_number}'

View File

@ -55,6 +55,22 @@ def hello_world():
print('Hello world!')
```
### Cross-Repository Issues
The action supports creating issues in a different repository than the one where the TODO comments are found. This requires:
1. Setting the `TARGET_REPO` input to specify the target repository (e.g., "owner/repo")
2. Providing a token with write access to the target repository via the `TOKEN` input
```yaml
- uses: alstr/todo-to-issue-action@v5
with:
TARGET_REPO: "my-org/target-repo"
TOKEN: ${{ secrets.CROSS_REPO_TOKEN }}
```
Note: When using a custom token for cross-repository access, it must be properly scoped with permissions to create issues in the target repository.
As per the [Google Style Guide](https://google.github.io/styleguide/cppguide.html#TODO_Comments), you can provide a _reference_ after the TODO identifier:
```python
@ -289,7 +305,7 @@ using the `LANGUAGES` input.
Just create a file that contains an array of languages, each with the following properties:
| Property | Description |
|------------|----------------------------------------------------------------------------------------------------------------------------------------------------|
| ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| language | The unique name of the language |
| extensions | A list of file extensions for the custom language |
| markers | A list of objects (see example below) to declare the comment markers. Make sure to escape all special Markdown characters with a double backslash. |
@ -535,6 +551,6 @@ Thanks to all those who have [contributed](https://github.com/alstr/todo-to-issu
## Supporting the Project
If youve found this action helpful and it has made your workflow easier, please consider buying a coffee to help keep it going. Thank you in advance!
If you've found this action helpful and it has made your workflow easier, please consider buying a coffee to help keep it going. Thank you in advance!
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/alstr18858)

View File

@ -2,8 +2,43 @@ name: 'TODO to Issue'
description: 'Converts IDE TODO comments to GitHub issues'
author: 'Alastair Mooney'
runs:
using: 'docker'
image: 'docker://ghcr.io/alstr/todo-to-issue-action:v5.1.12'
using: 'composite'
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: pip install requests ruamel.yaml
shell: bash
- name: Run TODO to Issue action
run: python ${{ github.action_path }}/main.py
shell: bash
env:
INPUT_REPO: ${{ inputs.REPO }}
INPUT_BEFORE: ${{ inputs.BEFORE }}
INPUT_COMMITS: ${{ inputs.COMMITS }}
INPUT_DIFF_URL: ${{ inputs.DIFF_URL }}
INPUT_SHA: ${{ inputs.SHA }}
INPUT_TOKEN: ${{ inputs.TOKEN }}
INPUT_CLOSE_ISSUES: ${{ inputs.CLOSE_ISSUES }}
INPUT_AUTO_P: ${{ inputs.AUTO_P }}
INPUT_PROJECT: ${{ inputs.PROJECT }}
INPUT_PROJECTS_SECRET: ${{ inputs.PROJECTS_SECRET }}
INPUT_IGNORE: ${{ inputs.IGNORE }}
INPUT_AUTO_ASSIGN: ${{ inputs.AUTO_ASSIGN }}
INPUT_ACTOR: ${{ inputs.ACTOR }}
INPUT_ISSUE_TEMPLATE: ${{ inputs.ISSUE_TEMPLATE }}
INPUT_IDENTIFIERS: ${{ inputs.IDENTIFIERS }}
INPUT_GITHUB_URL: ${{ inputs.GITHUB_URL }}
INPUT_GITHUB_SERVER_URL: ${{ inputs.GITHUB_SERVER_URL }}
INPUT_ESCAPE: ${{ inputs.ESCAPE }}
INPUT_LANGUAGES: ${{ inputs.LANGUAGES }}
INPUT_NO_STANDARD: ${{ inputs.NO_STANDARD }}
INPUT_INSERT_ISSUE_URLS: ${{ inputs.INSERT_ISSUE_URLS }}
INPUT_TARGET_REPO: ${{ inputs.TARGET_REPO }}
branding:
icon: 'check-square'
color: 'orange'
@ -31,15 +66,18 @@ inputs:
TOKEN:
description: 'The GitHub access token to allow us to retrieve, create and update issues (automatically set)'
required: false
default: ${{ github.token }}
default: '${{ github.token }}'
TARGET_REPO:
description: "Optional target repository to create issues in (e.g. 'owner/repo'). If not provided, issues will be created in the current repository."
required: false
CLOSE_ISSUES:
description: 'Optional input specifying whether to attempt to close an issue when a TODO is removed'
required: false
default: true
default: 'true'
AUTO_P:
description: 'For multiline TODOs, format each line as a new paragraph when creating the issue'
required: false
default: true
default: 'true'
PROJECT:
description: "User or organization project to link issues to, format 'project_type/owner/project_name'"
required: false
@ -52,7 +90,7 @@ inputs:
AUTO_ASSIGN:
description: 'Automatically assign new issues to the user who triggered the action'
required: false
default: false
default: 'false'
ACTOR:
description: 'The username of the person who triggered the action (automatically set)'
required: false
@ -74,15 +112,15 @@ inputs:
ESCAPE:
description: 'Escape all special Markdown characters'
required: false
default: true
default: 'true'
LANGUAGES:
description: 'A collection of comma-delimited URLs or local paths for custom language files'
required: false
NO_STANDARD:
description: "Exclude loading the default 'syntax.json' and 'languages.yml' files from the repository"
required: false
default: false
default: 'false'
INSERT_ISSUE_URLS:
description: 'Whether the action should insert the URL for a newly-created issue into the associated TODO comment'
required: false
default: false
default: 'false'