-
Notifications
You must be signed in to change notification settings - Fork 0
/
painter.rb
37 lines (28 loc) · 865 Bytes
/
painter.rb
1
2
3
4
5
6
7
8
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
require 'rugged'
class Painter
attr_accessor :repo
def initialize(repo)
@repo = repo
end
def self.first_sunday
days = 24*60*60
sunday = Time.now - 53*7*days
sunday += sunday.sunday? ? 0 : (7 - sunday.wday) * days
sunday
end
def commit(time:, message:, content:)
oid = repo.write(content, :blob)
index = repo.index
index.read_tree(repo.head.target.tree)
index.add(path: "canvas.txt", oid: oid, mode: 0100644)
options = {
tree: index.write_tree(repo),
author: { email: "[email protected]", name: 'Brandon Lilly', time: time },
committer: { email: "[email protected]", name: 'Brandon Lilly', time: time },
message: message,
parents: repo.empty? ? [] : [ repo.head.target ].compact,
update_ref: 'HEAD',
}
Rugged::Commit.create(repo, options)
end
end