Skip to content
Permalink
Browse files

Ignoring paused papers on dashboard counts

  • Loading branch information...
arfon committed May 11, 2019
1 parent 06e7597 commit 12e6f6e84f379d7c04e48c87b56a345a8012ccab
@@ -36,6 +36,10 @@ def title
payload['issue']['title']
end

def labels
payload['issue']['labels']
end

def comment_body
payload['comment']['body']
end
@@ -71,7 +75,7 @@ def assigned?
end

def labeled?
action == 'labeled'
action == 'labeled' || action == 'unlabeled'
end

def initialize_activities
@@ -93,7 +97,6 @@ def initialize_activities
# Parse the incoming payload and do something with it...
def parse_payload!
return if assigned?
return if labeled?
return if opened?
return if closed?

@@ -108,6 +111,17 @@ def parse_payload!
paper.save and return
end

# Parse the labels and update papers with the new labels.
if labeled?
new_labels = Hash.new
labels.each do |label|
new_labels.merge!(label['name'] => label['color'])
end

paper.labels = new_labels
paper.save and return
end

if pre_review?
kind = 'pre-review'
return if issue_number != paper.meta_review_issue_id
@@ -1,4 +1,21 @@
module HomeHelper
# How many papers should we show for an editor on the dashboard?
def in_progress_for_editor(papers)
ignored_state = "paused"
ignored_count = 0
papers.each do |p|
if p.labels.any? && p.labels.keys.include?(ignored_state)
ignored_count += 1
end
end

if ignored_count > 0
return "#{papers.count - ignored_count} (#{papers.count} inc. paused)"
else
return "#{papers.count}"
end
end

def current_class?(test_path)
return 'nav-link active' if request.path == test_path
'nav-link'
@@ -56,7 +56,7 @@
<% Editor.active.order('LOWER(login)').each do |editor| %>
<tr class="<%= cycle('odd', 'even') -%>">
<td><%= link_to editor.login, "/dashboard/#{editor.login}" %><% if editor.retired? %> <em>(emeritus)</em><% end %></td>
<td><%= Paper.in_progress.where(:editor => editor).count %></td>
<td><%= in_progress_for_editor(Paper.in_progress.where(:editor => editor)) %></td>
<td><%= editor.papers.visible.since(1.week.ago).count %></td>
<td><%= editor.papers.visible.since(1.month.ago).count %></td>
<td><%= editor.papers.visible.since(3.months.ago).count %></td>
@@ -0,0 +1,6 @@
class AddLabelsToPaper < ActiveRecord::Migration[5.2]
def change
add_column :papers, :labels, :jsonb, null: false, default: {}
add_index :papers, :labels, using: 'gin'
end
end
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2018_12_20_005508) do
ActiveRecord::Schema.define(version: 2019_05_11_114410) do

# These are extensions that must be enabled in order to support this database
enable_extension "hstore"
@@ -59,7 +59,9 @@
t.datetime "last_activity"
t.string "tags", default: [], array: true
t.string "languages", default: [], array: true
t.jsonb "labels", default: {}, null: false
t.index ["editor_id"], name: "index_papers_on_editor_id"
t.index ["labels"], name: "index_papers_on_labels", using: :gin
t.index ["languages"], name: "index_papers_on_languages", using: :gin
t.index ["last_activity"], name: "index_papers_on_last_activity"
t.index ["reviewers"], name: "index_papers_on_reviewers", using: :gin
@@ -20,6 +20,8 @@ def set_signature(payload)
let(:editor_review_comment) { json_fixture('editor-review-comment.json') }
let(:whedon_review_edit) { json_fixture('whedon-review-edit.json') }

let(:whedon_review_labeled) { json_fixture('whedon-review-labeled.json') }

let(:whedon_pre_review_comment_random) { json_fixture('whedon-pre-review-comment-random-review.json') }

describe "POST #github_recevier for REVIEW with invalid HTTP_X_HUB_SIGNATURE", :type => :request do
@@ -35,7 +37,7 @@ def set_signature(payload)
expect(@paper.activities).to eq({})
end
end

describe "POST #github_recevier for PRE-REVIEW", :type => :request do
before do
signature = set_signature(whedon_pre_review_opened)
@@ -67,6 +69,20 @@ def set_signature(payload)
end
end

describe "POST #github_recevier for REVIEW with labeling event", :type => :request do
before do
signature = set_signature(whedon_review_labeled)
@paper = create(:paper, :meta_review_issue_id => 78, :review_issue_id => 79, :labels => [{ "foo" => "efefef" }])
post '/dispatch', params: whedon_review_labeled, headers: { 'CONTENT_TYPE' => 'application/json', 'ACCEPT' => 'application/json', 'HTTP_X_HUB_SIGNATURE' => signature }
@paper.reload
end

it "should update the labels on the paper" do
expect(response).to be_ok
expect(@paper.labels).to eq({ "accepted" => "0052cc" })
end
end

describe "POST #github_recevier for REVIEW", :type => :request do
before do
signature = set_signature(whedon_review_opened)
@@ -0,0 +1,252 @@
{
"action": "unlabeled",
"issue": {
"url": "https://api.github.com/repos/openjournals/joss-reviews-testing/issues/79",
"repository_url": "https://api.github.com/repos/openjournals/joss-reviews-testing",
"labels_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/issues/79/labels{/name}",
"comments_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/issues/79/comments",
"events_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/issues/79/events",
"html_url": "https://github.com/openjournals/joss-reviews-testing/issues/79",
"id": 440505139,
"node_id": "MDU6SXNzdWU0NDA1MDUxMzk=",
"number": 79,
"title": "TEST",
"user": {
"login": "whedon",
"id": 18508068,
"node_id": "MDQ6VXNlcjE4NTA4MDY4",
"avatar_url": "https://avatars3.githubusercontent.com/u/18508068?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/whedon",
"html_url": "https://github.com/whedon",
"followers_url": "https://api.github.com/users/whedon/followers",
"following_url": "https://api.github.com/users/whedon/following{/other_user}",
"gists_url": "https://api.github.com/users/whedon/gists{/gist_id}",
"starred_url": "https://api.github.com/users/whedon/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/whedon/subscriptions",
"organizations_url": "https://api.github.com/users/whedon/orgs",
"repos_url": "https://api.github.com/users/whedon/repos",
"events_url": "https://api.github.com/users/whedon/events{/privacy}",
"received_events_url": "https://api.github.com/users/whedon/received_events",
"type": "User",
"site_admin": false
},
"labels": [
{
"id": 771671387,
"node_id": "MDU6TGFiZWw3NzE2NzEzODc=",
"url": "https://api.github.com/repos/openjournals/joss-reviews-testing/labels/accepted",
"name": "accepted",
"color": "0052cc",
"default": false
}
],
"state": "open",
"locked": false,
"assignee": {
"login": "arfon",
"id": 4483,
"node_id": "MDQ6VXNlcjQ0ODM=",
"avatar_url": "https://avatars1.githubusercontent.com/u/4483?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/arfon",
"html_url": "https://github.com/arfon",
"followers_url": "https://api.github.com/users/arfon/followers",
"following_url": "https://api.github.com/users/arfon/following{/other_user}",
"gists_url": "https://api.github.com/users/arfon/gists{/gist_id}",
"starred_url": "https://api.github.com/users/arfon/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/arfon/subscriptions",
"organizations_url": "https://api.github.com/users/arfon/orgs",
"repos_url": "https://api.github.com/users/arfon/repos",
"events_url": "https://api.github.com/users/arfon/events{/privacy}",
"received_events_url": "https://api.github.com/users/arfon/received_events",
"type": "User",
"site_admin": false
},
"assignees": [
{
"login": "arfon",
"id": 4483,
"node_id": "MDQ6VXNlcjQ0ODM=",
"avatar_url": "https://avatars1.githubusercontent.com/u/4483?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/arfon",
"html_url": "https://github.com/arfon",
"followers_url": "https://api.github.com/users/arfon/followers",
"following_url": "https://api.github.com/users/arfon/following{/other_user}",
"gists_url": "https://api.github.com/users/arfon/gists{/gist_id}",
"starred_url": "https://api.github.com/users/arfon/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/arfon/subscriptions",
"organizations_url": "https://api.github.com/users/arfon/orgs",
"repos_url": "https://api.github.com/users/arfon/repos",
"events_url": "https://api.github.com/users/arfon/events{/privacy}",
"received_events_url": "https://api.github.com/users/arfon/received_events",
"type": "User",
"site_admin": false
},
{
"login": "whedon",
"id": 18508068,
"node_id": "MDQ6VXNlcjE4NTA4MDY4",
"avatar_url": "https://avatars3.githubusercontent.com/u/18508068?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/whedon",
"html_url": "https://github.com/whedon",
"followers_url": "https://api.github.com/users/whedon/followers",
"following_url": "https://api.github.com/users/whedon/following{/other_user}",
"gists_url": "https://api.github.com/users/whedon/gists{/gist_id}",
"starred_url": "https://api.github.com/users/whedon/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/whedon/subscriptions",
"organizations_url": "https://api.github.com/users/whedon/orgs",
"repos_url": "https://api.github.com/users/whedon/repos",
"events_url": "https://api.github.com/users/whedon/events{/privacy}",
"received_events_url": "https://api.github.com/users/whedon/received_events",
"type": "User",
"site_admin": false
}
],
"milestone": null,
"comments": 0,
"created_at": "2019-05-05T23:58:19Z",
"updated_at": "2019-05-11T11:49:09Z",
"closed_at": null,
"author_association": "COLLABORATOR",
"body": "FOO"
},
"label": {
"id": 381284424,
"node_id": "MDU6TGFiZWwzODEyODQ0MjQ=",
"url": "https://api.github.com/repos/openjournals/joss-reviews-testing/labels/bug",
"name": "bug",
"color": "ee0701",
"default": true
},
"repository": {
"id": 59520368,
"node_id": "MDEwOlJlcG9zaXRvcnk1OTUyMDM2OA==",
"name": "joss-reviews-testing",
"full_name": "openjournals/joss-reviews-testing",
"private": true,
"owner": {
"login": "openjournals",
"id": 9032431,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjkwMzI0MzE=",
"avatar_url": "https://avatars3.githubusercontent.com/u/9032431?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/openjournals",
"html_url": "https://github.com/openjournals",
"followers_url": "https://api.github.com/users/openjournals/followers",
"following_url": "https://api.github.com/users/openjournals/following{/other_user}",
"gists_url": "https://api.github.com/users/openjournals/gists{/gist_id}",
"starred_url": "https://api.github.com/users/openjournals/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/openjournals/subscriptions",
"organizations_url": "https://api.github.com/users/openjournals/orgs",
"repos_url": "https://api.github.com/users/openjournals/repos",
"events_url": "https://api.github.com/users/openjournals/events{/privacy}",
"received_events_url": "https://api.github.com/users/openjournals/received_events",
"type": "Organization",
"site_admin": false
},
"html_url": "https://github.com/openjournals/joss-reviews-testing",
"description": null,
"fork": false,
"url": "https://api.github.com/repos/openjournals/joss-reviews-testing",
"forks_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/forks",
"keys_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/teams",
"hooks_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/hooks",
"issue_events_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/issues/events{/number}",
"events_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/events",
"assignees_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/assignees{/user}",
"branches_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/branches{/branch}",
"tags_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/tags",
"blobs_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/statuses/{sha}",
"languages_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/languages",
"stargazers_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/stargazers",
"contributors_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/contributors",
"subscribers_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/subscribers",
"subscription_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/subscription",
"commits_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/contents/{+path}",
"compare_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/merges",
"archive_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/downloads",
"issues_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/issues{/number}",
"pulls_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/pulls{/number}",
"milestones_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/milestones{/number}",
"notifications_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/labels{/name}",
"releases_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/releases{/id}",
"deployments_url": "https://api.github.com/repos/openjournals/joss-reviews-testing/deployments",
"created_at": "2016-05-23T21:43:02Z",
"updated_at": "2017-11-13T19:56:15Z",
"pushed_at": "2018-09-09T21:24:53Z",
"git_url": "git://github.com/openjournals/joss-reviews-testing.git",
"ssh_url": "git@github.com:openjournals/joss-reviews-testing.git",
"clone_url": "https://github.com/openjournals/joss-reviews-testing.git",
"svn_url": "https://github.com/openjournals/joss-reviews-testing",
"homepage": null,
"size": 3,
"stargazers_count": 0,
"watchers_count": 0,
"language": "Ruby",
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": true,
"has_pages": false,
"forks_count": 0,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 48,
"license": null,
"forks": 0,
"open_issues": 48,
"watchers": 0,
"default_branch": "test"
},
"organization": {
"login": "openjournals",
"id": 9032431,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjkwMzI0MzE=",
"url": "https://api.github.com/orgs/openjournals",
"repos_url": "https://api.github.com/orgs/openjournals/repos",
"events_url": "https://api.github.com/orgs/openjournals/events",
"hooks_url": "https://api.github.com/orgs/openjournals/hooks",
"issues_url": "https://api.github.com/orgs/openjournals/issues",
"members_url": "https://api.github.com/orgs/openjournals/members{/member}",
"public_members_url": "https://api.github.com/orgs/openjournals/public_members{/member}",
"avatar_url": "https://avatars3.githubusercontent.com/u/9032431?v=4",
"description": ""
},
"sender": {
"login": "arfon",
"id": 4483,
"node_id": "MDQ6VXNlcjQ0ODM=",
"avatar_url": "https://avatars1.githubusercontent.com/u/4483?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/arfon",
"html_url": "https://github.com/arfon",
"followers_url": "https://api.github.com/users/arfon/followers",
"following_url": "https://api.github.com/users/arfon/following{/other_user}",
"gists_url": "https://api.github.com/users/arfon/gists{/gist_id}",
"starred_url": "https://api.github.com/users/arfon/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/arfon/subscriptions",
"organizations_url": "https://api.github.com/users/arfon/orgs",
"repos_url": "https://api.github.com/users/arfon/repos",
"events_url": "https://api.github.com/users/arfon/events{/privacy}",
"received_events_url": "https://api.github.com/users/arfon/received_events",
"type": "User",
"site_admin": false
}
}

0 comments on commit 12e6f6e

Please sign in to comment.
You can’t perform that action at this time.