@@ -2,6 +2,7 @@ package api
22
33import (
44 "fmt"
5+ "time"
56)
67
78type IssuesPayload struct {
@@ -16,12 +17,13 @@ type IssuesAndTotalCount struct {
1617}
1718
1819type Issue struct {
19- Number int
20- Title string
21- URL string
22- State string
23- Body string
24- Comments struct {
20+ Number int
21+ Title string
22+ URL string
23+ State string
24+ Body string
25+ UpdatedAt time.Time
26+ Comments struct {
2527 TotalCount int
2628 }
2729 Author struct {
@@ -44,6 +46,7 @@ const fragments = `
4446 title
4547 url
4648 state
49+ updatedAt
4750 labels(first: 3) {
4851 nodes {
4952 name
@@ -111,19 +114,19 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa
111114 query($owner: String!, $repo: String!, $viewer: String!, $per_page: Int = 10) {
112115 repository(owner: $owner, name: $repo) {
113116 hasIssuesEnabled
114- assigned: issues(filterBy: {assignee: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT , direction: DESC}) {
117+ assigned: issues(filterBy: {assignee: $viewer, states: OPEN}, first: $per_page, orderBy: {field: UPDATED_AT , direction: DESC}) {
115118 totalCount
116119 nodes {
117120 ...issue
118121 }
119122 }
120- mentioned: issues(filterBy: {mentioned: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT , direction: DESC}) {
123+ mentioned: issues(filterBy: {mentioned: $viewer, states: OPEN}, first: $per_page, orderBy: {field: UPDATED_AT , direction: DESC}) {
121124 totalCount
122125 nodes {
123126 ...issue
124127 }
125128 }
126- authored: issues(filterBy: {createdBy: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT , direction: DESC}) {
129+ authored: issues(filterBy: {createdBy: $viewer, states: OPEN}, first: $per_page, orderBy: {field: UPDATED_AT , direction: DESC}) {
127130 totalCount
128131 nodes {
129132 ...issue
@@ -233,13 +236,15 @@ func IssueList(client *Client, ghRepo Repo, state string, labels []string, assig
233236func IssueByNumber (client * Client , ghRepo Repo , number int ) (* Issue , error ) {
234237 type response struct {
235238 Repository struct {
236- Issue Issue
239+ Issue Issue
240+ HasIssuesEnabled bool
237241 }
238242 }
239243
240244 query := `
241245 query($owner: String!, $repo: String!, $issue_number: Int!) {
242246 repository(owner: $owner, name: $repo) {
247+ hasIssuesEnabled
243248 issue(number: $issue_number) {
244249 title
245250 body
@@ -272,5 +277,9 @@ func IssueByNumber(client *Client, ghRepo Repo, number int) (*Issue, error) {
272277 return nil , err
273278 }
274279
280+ if ! resp .Repository .HasIssuesEnabled {
281+ return nil , fmt .Errorf ("the '%s/%s' repository has disabled issues" , ghRepo .RepoOwner (), ghRepo .RepoName ())
282+ }
283+
275284 return & resp .Repository .Issue , nil
276285}
0 commit comments