Skip to content

Commit

Permalink
Add ability to have a separate repository for issues
Browse files Browse the repository at this point in the history
ribtoks committed Jan 18, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 4eecdff commit 4504b9d
Showing 3 changed files with 31 additions and 17 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ You can use this action together with [parent issue updater](https://github.com/
| Input | Description |
|---|---|
| `REPO` | Repository name in the format of `owner/repo` (required) |
| `ISSUE_REPO` | Repository to create issues in (if empty, `REPO` is used) |
| `TOKEN` | Github [token](#security-token) used to create or close issues (required) |
| `REF` | Git ref: branch or pull request (required)|
| `SHA` | SHA-1 value of the commit (required) |
@@ -111,7 +112,7 @@ jobs:

Note escaped regex.

If you want to only process TODO comments from master branch, modify the workflow `on` section like this:
If you want to only process TODO comments from `master` branch, modify the workflow `on` section like this:

```yaml
on:
@@ -123,7 +124,7 @@ on:

### TODO comments

Comments are parsed using [tdg](https://github.com/ribtoks/tdg). Supported comments: `//`, `#`, `%`, `;`, `*`.
Comments are parsed using [tdg](https://gitlab.com/ribtoks/tdg). Supported comments: `//`, `#`, `%`, `;`, `*`.

Example of the comment (everything but the first line is optional):

@@ -132,4 +133,4 @@ Example of the comment (everything but the first line is optional):
// This is a multiline description of the issue
// that will be in the "Body" property of the comment

Note that second line has some optional "extensions" added as metadata to the issue by [tdg](https://github.com/ribtoks/tdg). Some are turned into labels and also used by [parent issue updater](https://github.com/ribtoks/parent-issue-update).
Note that second line has some optional "extensions" added as metadata to the issue by [tdg](https://gitlab.com/ribtoks/tdg). Some are turned into labels and also used by [parent issue updater](https://github.com/ribtoks/parent-issue-update).
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -3,7 +3,10 @@ description: "Sync TODO/BUG/FIXME comments with GitHub Issues and Projects"
author: "Taras Kushnir"
inputs:
REPO:
description: "Repository"
description: "Code repository"
default: ""
ISSUE_REPO:
description: "Repository for issues"
default: ""
TOKEN:
description: "Github token"
36 changes: 23 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
@@ -49,8 +49,10 @@ func sourceRoot(root string) string {

type env struct {
root string
owner string
repo string
codeOwner string
codeRepo string
issueOwner string
issueRepo string
label string
token string
sha string
@@ -92,12 +94,19 @@ func flagToBool(s string) bool {
}

func environment() *env {
r := strings.Split(os.Getenv("INPUT_REPO"), "/")
cr := strings.Split(os.Getenv("INPUT_REPO"), "/")
ir := strings.Split(os.Getenv("INPUT_ISSUE_REPO"), "/")
if len(ir) == 0 {
ir = cr
}

ref := os.Getenv("INPUT_REF")
e := &env{
ref: ref,
owner: r[0],
repo: r[1],
codeOwner: cr[0],
codeRepo: cr[1],
issueOwner: ir[0],
issueRepo: ir[1],
branch: branch(ref),
sha: os.Getenv("INPUT_SHA"),
root: os.Getenv("INPUT_ROOT"),
@@ -148,7 +157,8 @@ func environment() *env {
}

func (e *env) debugPrint() {
log.Printf("Repo: %v", e.repo)
log.Printf("Code repo: %v", e.codeRepo)
log.Printf("Issue repo: %v", e.issueRepo)
log.Printf("Ref: %v", e.ref)
log.Printf("Sha: %v", e.sha)
log.Printf("Root: %v", e.root)
@@ -188,7 +198,7 @@ func (s *service) fetchGithubIssues() ([]*github.Issue, error) {
}

for {
issues, resp, err := s.client.Issues.ListByRepo(s.ctx, s.env.owner, s.env.repo, opt)
issues, resp, err := s.client.Issues.ListByRepo(s.ctx, s.env.issueOwner, s.env.issueRepo, opt)
if err != nil {
return nil, err
}
@@ -248,7 +258,7 @@ func (s *service) createFileLink(c *tdglib.ToDoComment) string {

// https://github.com/{repo}/blob/{sha}/{file}#L{startLines}-L{endLine}
return fmt.Sprintf("https://github.com/%s/%s/blob/%s/%s#L%v-L%v",
s.env.owner, s.env.repo, s.env.sha, safeFilepath, start, end)
s.env.codeOwner, s.env.codeRepo, s.env.sha, safeFilepath, start, end)
}

func (s *service) labels(c *tdglib.ToDoComment) []string {
@@ -331,7 +341,7 @@ func (s *service) openNewIssues(issueMap map[string]*github.Issue, comments []*t
Labels: &labels,
}

issue, _, err := s.client.Issues.Create(s.ctx, s.env.owner, s.env.repo, req)
issue, _, err := s.client.Issues.Create(s.ctx, s.env.issueOwner, s.env.issueRepo, req)
if err != nil {
log.Printf("Error while creating an issue. err=%v", err)
continue
@@ -367,7 +377,7 @@ func (s *service) assignNewIssues() {
req := &github.IssueRequest{
Assignees: &[]string{assignee},
}
if _, _, err := s.client.Issues.Edit(s.ctx, s.env.owner, s.env.repo, issueNumber, req); err != nil {
if _, _, err := s.client.Issues.Edit(s.ctx, s.env.issueOwner, s.env.issueRepo, issueNumber, req); err != nil {
log.Printf("Error while assigning %v to issue %v. err=%v", assignee, issueNumber, err)
} else {
log.Printf("Successfully assigned %v to issue %v.", assignee, issueNumber)
@@ -383,7 +393,7 @@ func (s *service) retrieveCommitAuthor(commitHash string, title string) {
return
}

commit, _, err := s.client.Repositories.GetCommit(s.ctx, s.env.owner, s.env.repo, commitHash, &github.ListOptions{})
commit, _, err := s.client.Repositories.GetCommit(s.ctx, s.env.codeOwner, s.env.codeRepo, commitHash, &github.ListOptions{})
if err != nil {
log.Printf("Error while getting commit from commit hash. err=%v", err)
} else if commit != nil && commit.Author != nil && len(*commit.Author.Login) > 0 {
@@ -445,7 +455,7 @@ func (s *service) commentIssue(body string, i *github.Issue) {
comment := &github.IssueComment{
Body: &body,
}
_, _, err := s.client.Issues.CreateComment(s.ctx, s.env.owner, s.env.repo, i.GetNumber(), comment)
_, _, err := s.client.Issues.CreateComment(s.ctx, s.env.issueOwner, s.env.issueRepo, i.GetNumber(), comment)
if err != nil {
log.Printf("Error while adding a comment. issue=%v err=%v", i.ID, err)
return
@@ -495,7 +505,7 @@ func (s *service) closeMissingIssues(issueMap map[string]*github.Issue, comments
req := &github.IssueRequest{
State: &closed,
}
_, _, err := s.client.Issues.Edit(s.ctx, s.env.owner, s.env.repo, i.GetNumber(), req)
_, _, err := s.client.Issues.Edit(s.ctx, s.env.issueOwner, s.env.issueRepo, i.GetNumber(), req)

if err != nil {
log.Printf("Error while closing an issue. issue=%v err=%v", i.GetID(), err)

0 comments on commit 4504b9d

Please sign in to comment.