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
  • Loading branch information
ribtoks committed Jan 18, 2025
1 parent 4eecdff commit 4504b9d
Show file tree
Hide file tree
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
Expand Up @@ -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) |
Expand Down Expand Up @@ -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:
Expand All @@ -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):

Expand All @@ -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
Expand Up @@ -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"
Expand Down
36 changes: 23 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4504b9d

Please sign in to comment.