MCPcopy Create free account
hub / github.com/google/go-github / ListOAuthApps

Method ListOAuthApps

scrape/apps.go:49–80  ·  view source on GitHub ↗

ListOAuthApps lists the reviewed OAuth Applications for the specified organization (whether approved or denied).

(org string)

Source from the content-addressed store, hash-verified

47// ListOAuthApps lists the reviewed OAuth Applications for the
48// specified organization (whether approved or denied).
49func (c *Client) ListOAuthApps(org string) ([]*OAuthApp, error) {
50 doc, err := c.get("/organizations/%v/settings/oauth_application_policy", org)
51 if err != nil {
52 return nil, err
53 }
54
55 var apps []*OAuthApp
56 doc.Find(".oauth-application-allowlist ul > li").Each(func(_ int, s *goquery.Selection) {
57 var app OAuthApp
58 app.Name = s.Find(".request-info strong").First().Text()
59 app.Description = s.Find(".request-info .application-description").Text()
60
61 if editURL, ok := s.Find(".request-indicator a.edit-link").Attr("href"); ok {
62 app.ID = intFromLastPathSegment(editURL)
63 }
64
65 if r := s.Find(".request-indicator .requestor"); r.Length() > 0 {
66 app.State = OAuthAppRequested
67 app.RequestedBy = r.Text()
68 if editURL, ok := s.Find(".request-indicator a").Last().Attr("href"); ok {
69 app.ID = intFromLastPathSegment(editURL)
70 }
71 } else if r := s.Find(".request-indicator .approved-request"); r.Length() > 0 {
72 app.State = OAuthAppApproved
73 } else if r := s.Find(".request-indicator .denied-request"); r.Length() > 0 {
74 app.State = OAuthAppDenied
75 }
76 apps = append(apps, &app)
77 })
78
79 return apps, nil
80}
81
82func intFromLastPathSegment(s string) int {
83 seg := strings.Split(s, "/")

Callers 2

mainFunction · 0.95
Test_ListOAuthAppsFunction · 0.80

Calls 2

getMethod · 0.95
intFromLastPathSegmentFunction · 0.85

Tested by 1

Test_ListOAuthAppsFunction · 0.64