Skip to content

Commit

Permalink
Store last_synced_at on issues
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Jul 2, 2020
1 parent 528eb13 commit 4a4caa3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
8 changes: 3 additions & 5 deletions app/models/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def self.update_from_github(repo_full_name, remote_issue)
issue.milestone_name = remote_issue.milestone.try(:title)
issue.milestone_id = remote_issue.milestone.try(:number)
issue.labels = remote_issue.labels.map(&:name)
issue.save if issue.changed?
issue.last_synced_at = Time.zone.now
issue.save
rescue ArgumentError, Octokit::Error
# derp
end
Expand Down Expand Up @@ -128,10 +129,6 @@ def pull_request?
html_url && html_url.match?(/\/pull\//i)
end

def self.sync_pull_requests(time_range = 1.week.ago)
internal.pull_requests.where('issues.created_at > ?', time_range).where(merged_at: nil).find_each(&:download_pull_request)
end

def download_pull_request
return unless pull_request?
return if merged_at.present?
Expand Down Expand Up @@ -179,6 +176,7 @@ def sync
remote_issue = Issue.github_client.issue(repo_full_name, number)
Issue.update_from_github(repo_full_name, remote_issue)
update_extra_attributes
update_column(:last_synced_at, Time.zone.now)
rescue Octokit::NotFound
destroy
end
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20200702145622_add_last_synced_at_to_issues.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddLastSyncedAtToIssues < ActiveRecord::Migration[6.0]
def change
add_column :issues, :last_synced_at, :datetime
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_06_15_133314) do
ActiveRecord::Schema.define(version: 2020_07_02_145622) do

# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
enable_extension "plpgsql"

create_table "contributors", force: :cascade do |t|
Expand Down Expand Up @@ -76,6 +77,7 @@
t.datetime "first_response_at"
t.integer "response_time"
t.bigint "github_id"
t.datetime "last_synced_at"
t.index ["collabs"], name: "index_issues_on_collabs", using: :gin
t.index ["created_at"], name: "index_issues_on_created_at"
t.index ["org"], name: "index_issues_on_org"
Expand Down
5 changes: 0 additions & 5 deletions lib/tasks/issues.rake
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
namespace :issues do
task sync: :environment do
Issue.download_active_repos
Issue.sync_pull_requests
end

task sync_collabs: :environment do
Organization.collaborator.pluck(:name).each do |org|
Repository.sync_recently_active_repos(org)
Expand Down

0 comments on commit 4a4caa3

Please sign in to comment.