git-restart 0.0.6.pre.dev → 0.0.7dev

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30ed2f0ac7e53f499ea6129928d6735ef155761f
4
- data.tar.gz: '0079d01e8926c4e706dd9cd28f51763bafbd8a0a'
3
+ metadata.gz: ef8189ec5b0c60dd0d7f4c0bc87f7723f9896d09
4
+ data.tar.gz: 58bc594f1edf63ef4f4ea23a3cb5f4325433f6e3
5
5
  SHA512:
6
- metadata.gz: a3ad76a2c5b3c180a771f45d88bd5823a4a127ac5e41fc354a8e3afb172f63f2c408992e572c73b9152b895cf0d1d4e579eab4f1765b4702d99535019de46fa8
7
- data.tar.gz: 3d510191a2a96af5edff470bde9f07dfc92a342b7df67d3256d77cce0cd9e5bb6de16e2fa5b026733aa3afe79a6f51d69890294f3b02936a4fa4c0e82a80b3dd
6
+ metadata.gz: ec3fe1dd06650361126af62d93efab95bb30b9bfbe971c34be9c45332dbf8955e26f8e521df3b6fdb2b9784d4ee3c6e99b464a01592c47687caefa999f56f21b
7
+ data.tar.gz: 33fe46f6b69d6c534ad4ee362edd6c18b0665b5a606872efe3e78c9b13b70a90a58db9473cb254c02c105b6f805e7d8f13db53b3fea3906983f54116d8f3ba4d
@@ -1,6 +1,8 @@
1
1
 
2
2
  require 'mqtt/sub_handler'
3
+
3
4
  require 'git'
5
+ require 'octokit'
4
6
 
5
7
  require_relative "task.rb"
6
8
 
@@ -14,6 +16,7 @@ module GitRestart
14
16
  attr_reader :current_task_file
15
17
 
16
18
  attr_reader :mqtt
19
+ attr_accessor :octokit
17
20
 
18
21
  def current_commit()
19
22
  @git.object("HEAD^").sha;
@@ -41,15 +44,12 @@ module GitRestart
41
44
  yield(self);
42
45
 
43
46
  @listenedSub = @mqtt.subscribe_to "GitHub/#{@repo}" do |data|
44
- puts "Received data: #{data}"
45
47
  begin
46
48
  data = JSON.parse(data, symbolize_names: true);
47
49
  rescue
48
50
  next;
49
51
  end
50
52
 
51
- puts "Processing data #{data}"
52
-
53
53
  next unless data[:branch];
54
54
  if(not @branches.empty?)
55
55
  next unless @branches.include? data[:branch];
@@ -57,8 +57,6 @@ module GitRestart
57
57
  next if @exclude_branches.include? data[:branch];
58
58
  end
59
59
 
60
- puts "Queueing data!"
61
-
62
60
  @branchQueue << data;
63
61
  end
64
62
 
@@ -67,6 +65,15 @@ module GitRestart
67
65
  end
68
66
 
69
67
  def update_status(name, newStatus, message = nil)
68
+ return unless @octokit;
69
+
70
+ begin
71
+ @octokit.create_status(@repo, current_commit, newStatus, {
72
+ context: "#{@name}/#{name}".gsub(" ", "_"),
73
+ description: message,
74
+ })
75
+ rescue
76
+ end
70
77
  end
71
78
 
72
79
  def _start_task_thread()
@@ -74,8 +81,6 @@ module GitRestart
74
81
  loop do
75
82
  newData = @branchQueue.pop;
76
83
 
77
- puts "Popped data: #{newData}"
78
-
79
84
  @current_modified = newData[:touched];
80
85
  _switch_to(newData[:branch], newData[:head_commit]);
81
86
  end
@@ -108,23 +113,24 @@ module GitRestart
108
113
  t.gsub!(/^\.\//,"");
109
114
  @current_task_file = t;
110
115
 
111
- # TODO Add proper error reporting
112
116
  begin
113
117
  load(t);
114
118
  rescue ScriptError, StandardError
119
+ update_status("File #{t}", :failure, "File could not be parsed!")
115
120
  puts("File #{t} could not be loaded!");
116
121
  rescue GitRestart::TaskValidityError
122
+ update_status("File #{t}", :failure, "Task-file not configured properly!")
117
123
  puts("Task-File #{t} is not configured properly!");
118
124
  end
119
125
  end
120
126
 
121
- puts "Finished loading! Next tasks are: #{@next_tasks}"
127
+ puts "Finished loading! Next tasks: #{@next_tasks.keys}"
122
128
  end
123
129
 
124
130
  def _start_next_tasks()
125
131
  _generate_next_tasks();
126
132
 
127
- puts "Starting next tasks!"
133
+ puts "\n\nStarting next tasks!"
128
134
  @next_tasks.each do |name, t|
129
135
  next unless t.active;
130
136
  next unless t.triggered?
@@ -135,8 +141,12 @@ module GitRestart
135
141
  end
136
142
 
137
143
  def _switch_to(branch, commit = nil)
138
- puts "Switching to branch: #{branch}, commit: #{commit}"
139
- @git.fetch();
144
+ puts "\nSwitching to branch: #{branch}#{commit ? ",commit: #{commit}" : ""}"
145
+
146
+ begin
147
+ @git.fetch();
148
+ rescue
149
+ end
140
150
 
141
151
  if(branch != current_branch())
142
152
  _stop_all_tasks();
@@ -144,10 +154,10 @@ module GitRestart
144
154
  _stop_triggered_tasks();
145
155
  end
146
156
  @git.checkout(branch);
147
- @git.reset_hard(commit);
148
-
149
157
  @git.merge("origin/#{branch}");
150
158
 
159
+ @git.reset_hard(commit);
160
+
151
161
  _start_next_tasks();
152
162
  end
153
163
 
@@ -111,8 +111,10 @@ module GitRestart
111
111
  def start()
112
112
  puts "Starting Task: #{@name}"
113
113
 
114
- return if @targets.empty?
115
- sleep 0.01
114
+ if @targets.empty?
115
+ _report_status(:success, "No tasks to run!");
116
+ return
117
+ end
116
118
 
117
119
  @executionThread = Thread.new do
118
120
  _report_status(:pending);
@@ -142,6 +144,8 @@ module GitRestart
142
144
  end
143
145
  end
144
146
  @executionThread.abort_on_exception = true;
147
+
148
+ sleep 0.01
145
149
  end
146
150
 
147
151
  def stop()
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-restart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6.pre.dev
4
+ version: 0.0.7dev
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xasin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-05 00:00:00.000000000 Z
11
+ date: 2018-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mqtt-sub_handler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: octokit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: minitest
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -112,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
126
  version: 1.3.1
113
127
  requirements: []
114
128
  rubyforge_project:
115
- rubygems_version: 2.6.14.1
129
+ rubygems_version: 2.5.2.1
116
130
  signing_key:
117
131
  specification_version: 4
118
132
  summary: "(Re)start scripts and monitor them on a GitHub push"