diff --git a/Gemfile.lock b/Gemfile.lock index 208a9c8..2576a9a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - entitlements-github-plugin (0.4.3) + entitlements-github-plugin (0.4.4) contracts (~> 0.17.0) faraday (~> 2.0) faraday-retry (~> 2.0) diff --git a/lib/entitlements/service/github.rb b/lib/entitlements/service/github.rb index 3a440a6..33f7266 100644 --- a/lib/entitlements/service/github.rb +++ b/lib/entitlements/service/github.rb @@ -210,8 +210,8 @@ def members_and_roles_from_graphql login } role - cursor } + pageInfo { endCursor } } } }".gsub(/\n\s+/, "\n") @@ -222,14 +222,15 @@ def members_and_roles_from_graphql raise "GraphQL query failure" end - edges = response[:data].fetch("data").fetch("organization").fetch("membersWithRole").fetch("edges") + membersWithRole = response[:data].fetch("data").fetch("organization").fetch("membersWithRole") + edges = membersWithRole.fetch("edges") break unless edges.any? edges.each do |edge| result[edge.fetch("node").fetch("login").downcase] = edge.fetch("role") end - cursor = edges.last.fetch("cursor") + cursor = membersWithRole.fetch("pageInfo").fetch("endCursor") next if cursor && edges.size == max_graphql_results break end @@ -276,8 +277,8 @@ def pending_members_from_graphql node { login } - cursor } + pageInfo { endCursor } } } }".gsub(/\n\s+/, "\n") @@ -288,14 +289,15 @@ def pending_members_from_graphql raise "GraphQL query failure" end - edges = response[:data].fetch("data").fetch("organization").fetch("pendingMembers").fetch("edges") + pendingMembers = response[:data].fetch("data").fetch("organization").fetch("pendingMembers") + edges = pendingMembers.fetch("edges") break unless edges.any? edges.each do |edge| result.add(edge.fetch("node").fetch("login").downcase) end - cursor = edges.last.fetch("cursor") + cursor = pendingMembers.fetch("pageInfo").fetch("endCursor") next if cursor && edges.size == max_graphql_results break end diff --git a/lib/version.rb b/lib/version.rb index eaa9eb3..1578d44 100644 --- a/lib/version.rb +++ b/lib/version.rb @@ -2,6 +2,6 @@ module Entitlements module Version - VERSION = "0.4.3" + VERSION = "0.4.4" end end diff --git a/spec/acceptance/github-server/web.rb b/spec/acceptance/github-server/web.rb index 7273f3b..d9813c9 100644 --- a/spec/acceptance/github-server/web.rb +++ b/spec/acceptance/github-server/web.rb @@ -113,9 +113,11 @@ def graphql_org_query(query) edges = [] cursor_flag = cursor.nil? + end_cursor = nil result.each do |user, role| - next if !cursor_flag && Base64.strict_encode64(user) != cursor - edges << { "node" => { "login" => user }, "role" => role, "cursor" => Base64.strict_encode64(user) } if cursor_flag + end_cursor = Base64.strict_encode64(user) + next if !cursor_flag && end_cursor != cursor + edges << { "node" => { "login" => user }, "role" => role} if cursor_flag cursor_flag = true break if edges.size >= first end @@ -123,7 +125,10 @@ def graphql_org_query(query) { "organization" => { "membersWithRole" => { - "edges" => edges + "edges" => edges, + "pageInfo" => { + "endCursor" => end_cursor + } } } } @@ -144,9 +149,11 @@ def graphql_pending_query(query) edges = [] cursor_flag = cursor.nil? + end_cursor = nil result.each do |user| - next if !cursor_flag && Base64.strict_encode64(user) != cursor - edges << { "node" => { "login" => user }, "cursor" => Base64.strict_encode64(user) } if cursor_flag + end_cursor = Base64.strict_encode64(user) + next if !cursor_flag && end_cursor != cursor + edges << { "node" => { "login" => user } } if cursor_flag cursor_flag = true break if edges.size >= first end @@ -154,7 +161,10 @@ def graphql_pending_query(query) { "organization" => { "pendingMembers" => { - "edges" => edges + "edges" => edges, + "pageInfo" => { + "endCursor" => end_cursor + } } } } diff --git a/spec/unit/fixtures/graphql-output/organization-members-page1.json b/spec/unit/fixtures/graphql-output/organization-members-page1.json index 22e4150..562f988 100644 --- a/spec/unit/fixtures/graphql-output/organization-members-page1.json +++ b/spec/unit/fixtures/graphql-output/organization-members-page1.json @@ -7,24 +7,24 @@ "node": { "login": "monalisa" }, - "role": "ADMIN", - "cursor": "Y3Vyc29yOnYyOpEB" + "role": "ADMIN" }, { "node": { "login": "ocicat" }, - "role": "MEMBER", - "cursor": "Y3Vyc29yOnYyOpEF" + "role": "MEMBER" }, { "node": { "login": "blackmanx" }, - "role": "MEMBER", - "cursor": "Y3Vyc29yOnYyOpEG" + "role": "MEMBER" } - ] + ], + "pageInfo": { + "endCursor": "Y3Vyc29yOnYyOpEG" + } } } } diff --git a/spec/unit/fixtures/graphql-output/organization-members-page2.json b/spec/unit/fixtures/graphql-output/organization-members-page2.json index b7d5ce9..be03e12 100644 --- a/spec/unit/fixtures/graphql-output/organization-members-page2.json +++ b/spec/unit/fixtures/graphql-output/organization-members-page2.json @@ -7,24 +7,24 @@ "node": { "login": "toyger" }, - "role": "MEMBER", - "cursor": "Y3Vyc29yOnYyOpEH" + "role": "MEMBER" }, { "node": { "login": "highlander" }, - "role": "MEMBER", - "cursor": "Y3Vyc29yOnYyOpEI" + "role": "MEMBER" }, { "node": { "login": "RussianBlue" }, - "role": "MEMBER", - "cursor": "Y3Vyc29yOnYyOpEJ" + "role": "MEMBER" } - ] + ], + "pageInfo": { + "endCursor": "Y3Vyc29yOnYyOpEJ" + } } } } diff --git a/spec/unit/fixtures/graphql-output/organization-members-page3.json b/spec/unit/fixtures/graphql-output/organization-members-page3.json index 0280049..49316ce 100644 --- a/spec/unit/fixtures/graphql-output/organization-members-page3.json +++ b/spec/unit/fixtures/graphql-output/organization-members-page3.json @@ -7,24 +7,24 @@ "node": { "login": "ragamuffin" }, - "role": "MEMBER", - "cursor": "Y3Vyc29yOnYyOpEK" + "role": "MEMBER" }, { "node": { "login": "mainecoon" }, - "role": "MEMBER", - "cursor": "Y3Vyc29yOnYyOpEL" + "role": "MEMBER" }, { "node": { "login": "laperm" }, - "role": "MEMBER", - "cursor": "Y3Vyc29yOnYyOpEM" + "role": "MEMBER" } - ] + ], + "pageInfo": { + "endCursor": "Y3Vyc29yOnYyOpEM" + } } } } diff --git a/spec/unit/fixtures/graphql-output/organization-members-page4.json b/spec/unit/fixtures/graphql-output/organization-members-page4.json index f5e6510..ac263d2 100644 --- a/spec/unit/fixtures/graphql-output/organization-members-page4.json +++ b/spec/unit/fixtures/graphql-output/organization-members-page4.json @@ -7,10 +7,12 @@ "node": { "login": "peterbald" }, - "role": "MEMBER", - "cursor": "Y3Vyc29yOnYyOpEN" + "role": "MEMBER" } - ] + ], + "pageInfo": { + "endCursor": "Y3Vyc29yOnYyOpEN" + } } } } diff --git a/spec/unit/fixtures/graphql-output/pending-members-page1.json b/spec/unit/fixtures/graphql-output/pending-members-page1.json index 76bd191..01d65c3 100644 --- a/spec/unit/fixtures/graphql-output/pending-members-page1.json +++ b/spec/unit/fixtures/graphql-output/pending-members-page1.json @@ -6,22 +6,22 @@ { "node": { "login": "alice" - }, - "cursor": "Y3Vyc29yOnYyOpEB" + } }, { "node": { "login": "bob" - }, - "cursor": "Y3Vyc29yOnYyOpEF" + } }, { "node": { "login": "charles" - }, - "cursor": "Y3Vyc29yOnYyOpEG" } - ] + } + ], + "pageInfo": { + "endCursor": "Y3Vyc29yOnYyOpEG" + } } } } diff --git a/spec/unit/fixtures/graphql-output/pending-members-page2.json b/spec/unit/fixtures/graphql-output/pending-members-page2.json index 33fc8cc..63c8335 100644 --- a/spec/unit/fixtures/graphql-output/pending-members-page2.json +++ b/spec/unit/fixtures/graphql-output/pending-members-page2.json @@ -6,22 +6,22 @@ { "node": { "login": "DAVID" - }, - "cursor": "Y3Vyc29yOnYyOpEH" + } }, { "node": { "login": "edward" - }, - "cursor": "Y3Vyc29yOnYyOpEI" + } }, { "node": { "login": "frank" - }, - "cursor": "Y3Vyc29yOnYyOpEJ" + } } - ] + ], + "pageInfo": { + "endCursor": "Y3Vyc29yOnYyOpEJ" + } } } } diff --git a/spec/unit/fixtures/graphql-output/pending-members-page3.json b/spec/unit/fixtures/graphql-output/pending-members-page3.json index 92b1ea7..74c7887 100644 --- a/spec/unit/fixtures/graphql-output/pending-members-page3.json +++ b/spec/unit/fixtures/graphql-output/pending-members-page3.json @@ -6,22 +6,22 @@ { "node": { "login": "george" - }, - "cursor": "Y3Vyc29yOnYyOpEK" + } }, { "node": { "login": "harriet" - }, - "cursor": "Y3Vyc29yOnYyOpEL" + } }, { "node": { "login": "ingrid" - }, - "cursor": "Y3Vyc29yOnYyOpEM" + } } - ] + ], + "pageInfo": { + "endCursor": "Y3Vyc29yOnYyOpEM" + } } } } diff --git a/spec/unit/fixtures/graphql-output/pending-members-page4.json b/spec/unit/fixtures/graphql-output/pending-members-page4.json index 79e9ab1..4095a30 100644 --- a/spec/unit/fixtures/graphql-output/pending-members-page4.json +++ b/spec/unit/fixtures/graphql-output/pending-members-page4.json @@ -6,10 +6,12 @@ { "node": { "login": "blackmanx" - }, - "cursor": "Y3Vyc29yOnYyOpEN" + } } - ] + ], + "pageInfo": { + "endCursor": "Y3Vyc29yOnYyOpEN" + } } } }