Class: NetworkProfile::GithubProject

Inherits:
DefaultProfile show all
Includes:
GithubGraphql
Defined in:
lib/network_profile/extractors/github_project.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from GithubGraphql

#doc, #json, #query!

Methods inherited from DefaultProfile

all_types, auto_extractor_link_types, #data, #initialize, parse

Constructor Details

This class inherits a constructor from NetworkProfile::DefaultProfile

Class Method Details

.handle?(link) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/network_profile/extractors/github_project.rb', line 8

def self.handle?(link)
  link.to_s[%r{github.com/[^/]+/.+}] && NetworkProfile.github_api_key
end

Instance Method Details

#extra_dataObject



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/network_profile/extractors/github_project.rb', line 74

def extra_data
  {
    watchers: json.dig('data', 'repository', 'watchers', 'totalCount'),
    forks: json.dig('data', 'repository', 'forkCount'),
    stars: json.dig('data', 'repository', 'stargazers', 'totalCount'),
    issue_count: json.dig('data', 'repository', 'issues', 'totalCount'),
    commits: json.dig('data', 'repository', 'defaultBranchRef', 'target', 'history', 'totalCount'),
    license: json.dig('data', 'repository', 'licenseInfo', 'name'),
    created: Time.parse(json.dig('data', 'repository', 'createdAt')).to_date,
    language_bytes: json.dig('data', 'repository', 'languages', 'edges')&.map { |l| [l.dig('node', 'name'), l['size']] }&.sort_by { |_a, b| -b },
    last_commit: last_commit
  }
end

#imageObject



70
71
72
# File 'lib/network_profile/extractors/github_project.rb', line 70

def image
  nil
end

#last_commitObject



66
67
68
# File 'lib/network_profile/extractors/github_project.rb', line 66

def last_commit
  Time.parse(json.dig('data', 'repository', 'defaultBranchRef', 'target', 'committedDate')).to_date
end

#queryObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/network_profile/extractors/github_project.rb', line 12

def query
  _, author, repo = @link.match(%r{github.com/([^/]+)/([^/\?]+)(\.git)?}).to_a
  <<~DOC
    query {
      repository(name:"#{repo}", owner: "#{author}") {
        createdAt
        description
        nameWithOwner
        updatedAt
        languages(first:10) {
          edges {
            node {
              name
            }
            size
          }
          totalCount
        }
        licenseInfo { name }
        forkCount
        isFork
        defaultBranchRef {
          name
          target {
            ... on Commit {
              committedDate
              history(first: 0) {
                totalCount
              }
            }
          }
        }
        issues {
          totalCount
        }
        stargazers {
          totalCount
        }
        watchers {
          totalCount
        }
      }
    }
  DOC
end

#textObject



62
63
64
# File 'lib/network_profile/extractors/github_project.rb', line 62

def text
  json.dig('data', 'repository', 'description')
end

#titleObject



58
59
60
# File 'lib/network_profile/extractors/github_project.rb', line 58

def title
  json.dig('data', 'repository', 'nameWithOwner')
end