theoj 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '09237502c90ed400980274941c03683a2f5b33eaa911debc8b9d50d0747e5a91'
4
+ data.tar.gz: eb959c2aa0821a45246d3a7551f1fc265c0dc571c9ce791840e7465fc5bb6045
5
+ SHA512:
6
+ metadata.gz: 877313b88d2739e7076ec44b18e7efe50026f099f0e2a55e95919aa2af8ea8d72edbb35ee4882154c650b79134bbb72cdf2780f26e8daa64d06a7505ecd91e26
7
+ data.tar.gz: 54b6835727136c213a5339d303000bc6f2ee47e8ae24118a3577c2e70657a36613417397074bf7228ffd66a6b3949df0fd7b91649e06be4ba9bdb3b7664ec5b2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Juanjo Bazán
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # The Open Journal
2
+ A library to manage editorial objects used by the open journals review process
3
+
4
+ [![CI](https://github.com/xuanxu/theoj/actions/workflows/ci.yml/badge.svg)](https://github.com/xuanxu/theoj/actions/workflows/ci.yml)
@@ -0,0 +1,17 @@
1
+ module Theoj
2
+ class Author
3
+ attr_accessor :name
4
+ attr_accessor :orcid
5
+ attr_accessor :affiliation
6
+
7
+ def initialize(name, orcid, affiliation)
8
+ @name = name
9
+ @orcid = orcid
10
+ @affiliation = affiliation
11
+ end
12
+
13
+ def validate_orcid
14
+ end
15
+
16
+ end
17
+ end
data/lib/theoj/git.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'open3'
2
+ require 'fileutils'
3
+
4
+ module Theoj
5
+ module Git
6
+ def clone_repo(url, local_path)
7
+ url = URI.extract(url.to_s).first
8
+ return false if url.nil?
9
+
10
+ FileUtils.mkdir_p(local_path)
11
+ stdout, stderr, status = Open3.capture3 "git clone #{url} #{local_path}"
12
+ status.success?
13
+ end
14
+
15
+ def change_branch(branch, local_path)
16
+ return true if (branch.nil? || branch.strip.empty?)
17
+ stdout, stderr, status = Open3.capture3 "git -C #{local_path} checkout #{branch}"
18
+ status.success?
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,63 @@
1
+ require "octokit"
2
+
3
+ # This module includes all the methods involving calls to the GitHub API
4
+ # It reuses a memoized Octokit::Client instance
5
+ module Theoj
6
+ module GitHub
7
+
8
+ # Authenticated Octokit
9
+ def github_client
10
+ @github_client ||= Octokit::Client.new(access_token: github_access_token, auto_paginate: true)
11
+ end
12
+
13
+ # GitHub access token
14
+ def github_access_token
15
+ @github_access_token ||= ENV["GH_ACCESS_TOKEN"]
16
+ end
17
+
18
+ # GitHub API headers
19
+ def github_headers
20
+ @github_headers ||= { "Authorization" => "token #{github_access_token}",
21
+ "Content-Type" => "application/json",
22
+ "Accept" => "application/vnd.github.v3+json" }
23
+ end
24
+
25
+ # Return an Octokit GitHub Issue
26
+ def issue(repo, issue_id)
27
+ @issue ||= github_client.issue(repo, issue_id)
28
+ end
29
+
30
+ # List labels of a GitHub issue
31
+ def issue_labels(repo, issue_id)
32
+ github_client.labels_for_issue(repo, issue_id).map { |l| l[:name] }
33
+ end
34
+
35
+ # Uses the GitHub API to determine if a user is already a collaborator of the repo
36
+ def is_collaborator?(repo, username)
37
+ username = user_login(username)
38
+ github_client.collaborator?(repo, username)
39
+ end
40
+
41
+ # Uses the GitHub API to determine if a user is already a collaborator of the repo
42
+ def can_be_assignee?(repo, username)
43
+ username = user_login(username)
44
+ github_client.check_assignee(repo, username)
45
+ end
46
+
47
+ # Uses the GitHub API to determine if a user has a pending invitation
48
+ def is_invited?(repo, username)
49
+ username = user_login(username)
50
+ github_client.repository_invitations(repo).any? { |i| i.invitee.login.downcase == username }
51
+ end
52
+
53
+ # Returns the user login (removes the @ from the username)
54
+ def user_login(username)
55
+ username.strip.sub(/^@/, "").downcase
56
+ end
57
+
58
+ # Returns true if the string is a valid GitHub isername (starts with @)
59
+ def username?(username)
60
+ username.match?(/\A@/)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,75 @@
1
+ require 'find'
2
+
3
+ module Theoj
4
+ class Paper
5
+ include Theoj::Git
6
+
7
+ attr_accessor :review_issue
8
+ attr_accessor :repository
9
+ attr_accessor :paper_path
10
+
11
+ def initialize(repository, branch, path = nil)
12
+ @repository = repository
13
+ @branch = branch
14
+ find_paper path
15
+ end
16
+
17
+ def find_paper(path)
18
+ if path.to_s.strip.empty?
19
+ setup_local_repo
20
+ @paper_path = Theoj::Paper.find_paper_path(local_path)
21
+ cleanup
22
+ else
23
+ @paper_path = path
24
+ end
25
+ end
26
+
27
+ def authors
28
+ []
29
+ end
30
+
31
+ def self.find_paper_path(search_path)
32
+ paper_path = nil
33
+
34
+ if Dir.exist? search_path
35
+ Find.find(search_path).each do |path|
36
+ if path =~ /paper\.tex$|paper\.md$/
37
+ paper_path = path
38
+ break
39
+ end
40
+ end
41
+ end
42
+
43
+ paper_path
44
+ end
45
+
46
+ def self.from_repo(repository, branch = "main")
47
+ Paper.new(repository, branch, nil)
48
+ end
49
+
50
+ private
51
+ def setup_local_repo
52
+ msg_no_repo = "Downloading of the repository failed. Please make sure the URL is correct."
53
+ msg_no_branch = "Couldn't check the bibtex because branch name is incorrect: #{paper_branch.to_s}"
54
+
55
+ error = clone_repo(target_repository, local_path) ? nil : msg_no_repo
56
+ (error = change_branch(paper_branch, local_path) ? nil : msg_no_branch) unless error
57
+
58
+ failure(error) if error
59
+ error.nil?
60
+ end
61
+
62
+ def local_path
63
+ @local_path ||= "tmp/#{SecureRandom.hex}"
64
+ end
65
+
66
+ def cleanup
67
+ FileUtils.rm_rf(local_path) if Dir.exist?(local_path)
68
+ end
69
+
70
+ def failure(msg)
71
+ cleanup
72
+ raise(msg)
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,50 @@
1
+ require "securerandom"
2
+
3
+ module Theoj
4
+ class ReviewIssue
5
+ include Theoj::GitHub
6
+
7
+ attr_accessor :issue_id
8
+ attr_accessor :repository
9
+ attr_accessor :paper
10
+ attr_accessor :local_path
11
+
12
+ def initialize(repository, issue_id, access_token=nil)
13
+ @issue_id = issue_id
14
+ @repository = repository
15
+ @github_access_token = access_token
16
+ end
17
+
18
+ def issue_body
19
+ issue(repository, issue_id).body
20
+ end
21
+
22
+ def paper
23
+ end
24
+
25
+ def target_repository
26
+ @target_repository ||= read_value_from_body("target-repository")
27
+ end
28
+
29
+ def paper_branch
30
+ @paper_branch ||= read_value_from_body("branch")
31
+ end
32
+
33
+ private
34
+
35
+ def read_from_body(start_mark, end_mark)
36
+ text = ""
37
+ issue_body.match(/#{start_mark}(.*)#{end_mark}/im) do |m|
38
+ text = m[1]
39
+ end
40
+ text.strip
41
+ end
42
+
43
+ # Read value in issue's body between HTML comments
44
+ def read_value_from_body(value_name)
45
+ start_mark = "<!--#{value_name}-->"
46
+ end_mark = "<!--end-#{value_name}-->"
47
+ read_from_body(start_mark, end_mark)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module Theoj
2
+ VERSION = "0.0.1"
3
+ end
data/lib/theoj.rb ADDED
@@ -0,0 +1,9 @@
1
+ require_relative "theoj/version"
2
+ require_relative "theoj/git"
3
+ require_relative "theoj/github"
4
+ require_relative "theoj/review_issue"
5
+ require_relative "theoj/paper"
6
+ require_relative "theoj/author"
7
+
8
+ module Theoj
9
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: theoj
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Juanjo Bazán
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-09-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octokit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.21'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.21'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 13.0.6
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 13.0.6
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.10'
55
+ description: A library to manage editorial objects used in the Open Journals' review
56
+ process
57
+ email:
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE
63
+ - README.md
64
+ - lib/theoj.rb
65
+ - lib/theoj/author.rb
66
+ - lib/theoj/git.rb
67
+ - lib/theoj/github.rb
68
+ - lib/theoj/paper.rb
69
+ - lib/theoj/review_issue.rb
70
+ - lib/theoj/version.rb
71
+ homepage: http://github.com/xuanxu/theoj
72
+ licenses:
73
+ - MIT
74
+ metadata:
75
+ bug_tracker_uri: https://github.com/xuanxu/theoj/issues
76
+ changelog_uri: https://github.com/xuanxu/theoj/blob/master/CHANGELOG.md
77
+ documentation_uri: https://www.rubydoc.info/gems/theoj
78
+ homepage_uri: http://github.com/xuanxu/theoj
79
+ source_code_uri: http://github.com/xuanxu/theoj
80
+ post_install_message:
81
+ rdoc_options:
82
+ - "--main"
83
+ - README.md
84
+ - "--charset=UTF-8"
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubygems_version: 3.2.22
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Editorial objects used by the Open Journals
102
+ test_files: []