@@ -26,12 +26,6 @@ type IssueLabel struct {
2626 Name string
2727}
2828
29- type apiIssues struct {
30- Issues struct {
31- Nodes []Issue
32- }
33- }
34-
3529const fragments = `
3630 fragment issue on Issue {
3731 number
@@ -47,12 +41,8 @@ const fragments = `
4741 }
4842`
4943
50- func IssueCreate (client * Client , ghRepo Repo , params map [string ]interface {}) (* Issue , error ) {
51- repoID , err := GitHubRepoId (client , ghRepo )
52- if err != nil {
53- return nil , err
54- }
55-
44+ // IssueCreate creates an issue in a GitHub repository
45+ func IssueCreate (client * Client , repo * Repository , params map [string ]interface {}) (* Issue , error ) {
5646 query := `
5747 mutation CreateIssue($input: CreateIssueInput!) {
5848 createIssue(input: $input) {
@@ -63,7 +53,7 @@ func IssueCreate(client *Client, ghRepo Repo, params map[string]interface{}) (*I
6353 }`
6454
6555 inputParams := map [string ]interface {}{
66- "repositoryId" : repoID ,
56+ "repositoryId" : repo . ID ,
6757 }
6858 for key , val := range params {
6959 inputParams [key ] = val
@@ -78,7 +68,7 @@ func IssueCreate(client *Client, ghRepo Repo, params map[string]interface{}) (*I
7868 }
7969 }{}
8070
81- err = client .GraphQL (query , variables , & result )
71+ err : = client .GraphQL (query , variables , & result )
8272 if err != nil {
8373 return nil , err
8474 }
@@ -88,36 +78,41 @@ func IssueCreate(client *Client, ghRepo Repo, params map[string]interface{}) (*I
8878
8979func IssueStatus (client * Client , ghRepo Repo , currentUsername string ) (* IssuesPayload , error ) {
9080 type response struct {
91- Assigned apiIssues
92- Mentioned apiIssues
93- Authored apiIssues
81+ Repository struct {
82+ Assigned struct {
83+ Nodes []Issue
84+ }
85+ Mentioned struct {
86+ Nodes []Issue
87+ }
88+ Authored struct {
89+ Nodes []Issue
90+ }
91+ HasIssuesEnabled bool
92+ }
9493 }
9594
9695 query := fragments + `
97- query($owner: String!, $repo: String!, $viewer: String!, $per_page: Int = 10) {
98- assigned: repository(owner: $owner, name: $repo) {
99- issues(filterBy: {assignee: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
100- nodes {
101- ...issue
102- }
103- }
104- }
105- mentioned: repository(owner: $owner, name: $repo) {
106- issues(filterBy: {mentioned: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
107- nodes {
108- ...issue
109- }
110- }
111- }
112- authored: repository(owner: $owner, name: $repo) {
113- issues(filterBy: {createdBy: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
114- nodes {
115- ...issue
116- }
117- }
118- }
119- }
120- `
96+ query($owner: String!, $repo: String!, $viewer: String!, $per_page: Int = 10) {
97+ repository(owner: $owner, name: $repo) {
98+ hasIssuesEnabled
99+ assigned: issues(filterBy: {assignee: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
100+ nodes {
101+ ...issue
102+ }
103+ }
104+ mentioned: issues(filterBy: {mentioned: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
105+ nodes {
106+ ...issue
107+ }
108+ }
109+ authored: issues(filterBy: {createdBy: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
110+ nodes {
111+ ...issue
112+ }
113+ }
114+ }
115+ }`
121116
122117 owner := ghRepo .RepoOwner ()
123118 repo := ghRepo .RepoName ()
@@ -133,10 +128,14 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa
133128 return nil , err
134129 }
135130
131+ if ! resp .Repository .HasIssuesEnabled {
132+ return nil , fmt .Errorf ("the '%s/%s' repository has disabled issues" , owner , repo )
133+ }
134+
136135 payload := IssuesPayload {
137- Assigned : resp .Assigned . Issues .Nodes ,
138- Mentioned : resp .Mentioned . Issues .Nodes ,
139- Authored : resp .Authored . Issues .Nodes ,
136+ Assigned : resp .Repository . Assigned .Nodes ,
137+ Mentioned : resp .Repository . Mentioned .Nodes ,
138+ Authored : resp .Repository . Authored .Nodes ,
140139 }
141140
142141 return & payload , nil
@@ -171,6 +170,7 @@ func IssueList(client *Client, ghRepo Repo, state string, labels []string, assig
171170 query := fragments + `
172171 query($owner: String!, $repo: String!, $limit: Int, $states: [IssueState!] = OPEN, $labels: [String!], $assignee: String) {
173172 repository(owner: $owner, name: $repo) {
173+ hasIssuesEnabled
174174 issues(first: $limit, orderBy: {field: CREATED_AT, direction: DESC}, states: $states, labels: $labels, filterBy: {assignee: $assignee}) {
175175 nodes {
176176 ...issue
@@ -192,14 +192,23 @@ func IssueList(client *Client, ghRepo Repo, state string, labels []string, assig
192192 }
193193
194194 var resp struct {
195- Repository apiIssues
195+ Repository struct {
196+ Issues struct {
197+ Nodes []Issue
198+ }
199+ HasIssuesEnabled bool
200+ }
196201 }
197202
198203 err := client .GraphQL (query , variables , & resp )
199204 if err != nil {
200205 return nil , err
201206 }
202207
208+ if ! resp .Repository .HasIssuesEnabled {
209+ return nil , fmt .Errorf ("the '%s/%s' repository has disabled issues" , owner , repo )
210+ }
211+
203212 return resp .Repository .Issues .Nodes , nil
204213}
205214
0 commit comments