Module: GitlabToDoap::XML

Included in:
GitlabToDoap
Defined in:
lib/gitlab-to-doap/xml.rb

Overview

This is the real meat and potatoes of the project.

Instance Method Summary collapse

Instance Method Details

#doap_xml(project) ⇒ Object



9
10
11
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/gitlab-to-doap/xml.rb', line 9

def doap_xml(project)
  # TODO: add a version tag for the latest release
  # project_releases = gitlab.project_releases project["id"]
  # latest_release = project_releases[0]
  # TODO: or failing that, the latest git tag?

  languages = gitlab.get("/projects/#{project["id"]}/languages")
  users = gitlab.get("/projects/#{gitlab.url_encode project["id"]}/users")

  builder = Builder::XmlMarkup.new(indent: 2)
  builder.instruct!

  builder.Project(xmlns: "http://usefulinc.com/ns/doap#",
                  "xmlns:rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
                  "xmlns:foaf": "http://xmlns.com/foaf/0.1/") do |proj|
    proj.name project.name
    proj.shortdesc strip_markdown(project.description)
    proj.homepage("rdf:resource": project.web_url)
    proj.created DateTime.parse(project.created_at).strftime("%Y-%m-%d")

    proj.repository do |repo|
      repo.GitRepository do |git|
        git.location("rdf:resource": project.http_url_to_repo)
        git.browse("rdf:resource": project.web_url + "/-/tree/#{project.default_branch}")
      end
    end

    proj.tag! :"download-page", "rdf:resource": project.web_url

    if project.issues_enabled
      proj.tag! :"bug-database", "rdf:resource": "#{project.web_url}/-/issues"
    end

    languages.to_hash.each do |language, _percentage|
      # XXX: filter based on percentage, only showing languages >10%?
      proj.tag! :"programming-language", language
    end

    if project.wiki_enabled
      proj.wiki("rdf:resource": project.web_url + "/-/wikis/home")
    end

    project.tag_list.each do |tag|
      url = URI.parse(project.web_url)
      url.path = "/explore/projects"
      url.query = "tag=#{tag}"
      proj.category("rdf:resource": url.to_s)
    end

    if project.license
      proj.license("rdf:resource": project.license.source_url)
    end

    users.each do |proj_user|
      proj.maintainer do |maintainer|
        maintainer.foaf :Person do |person|
          user = gitlab.user(proj_user.id)
          person.foaf :name, user.name
          if user.public_email != ""
            person.foaf :mbox, "rdf:resource": "mailto:#{user.public_email}"
          end
          if user.website_url != ""
            person.foaf :homepage, "rdf:resource": user.website_url
          end
          person.foaf :homepage, "rdf:resource": user.web_url
        end
      end
    end
  end
end