@@ -3,6 +3,8 @@ package com.hcyacg.github
3
3
import com.alibaba.fastjson.JSONObject
4
4
import com.hcyacg.GithubNotice
5
5
import com.hcyacg.GithubTask
6
+ import com.hcyacg.GithubTask.Companion.all
7
+ import com.hcyacg.GithubTask.Companion.branches
6
8
import com.hcyacg.GithubTask.Companion.groups
7
9
import com.hcyacg.GithubTask.Companion.logger
8
10
import com.hcyacg.GithubTask.Companion.num
@@ -39,19 +41,16 @@ class Commits {
39
41
suspend fun checkUpdate (
40
42
projects : Any? ,
41
43
branch : Any? ,
42
- index : Int
43
44
) {
44
45
var name: Any? = null
45
46
var time: Any? = null
46
47
var html: Any? = null
47
48
var avatar: Any? = null
48
49
var message: Any? = null
49
50
var stA: String? = null
50
- var sha1: Any? = null
51
51
var response: Response ? = null
52
52
// logger.warning("${projects.toString()} => ${branch.toString()}")
53
53
val bots = Bot .instances
54
-
55
54
try {
56
55
val request: Request = Request .Builder ()
57
56
.url(" https://api.github.com/repos/${projects.toString()} /commits/${branch.toString()} " )
@@ -66,11 +65,17 @@ class Commits {
66
65
val jsonObject: JSONObject ? = JSONObject .parseObject(stA)
67
66
68
67
if (null != jsonObject) {
69
- val sha1: Any? = jsonObject[" sha" ]
70
- if (sha[projects].contentEquals(sha1.toString())) {
68
+ if (sha[" ${projects} /$branch " ].contentEquals(jsonObject[" sha" ].toString())) {
69
+ return
70
+ }
71
+ if (null == sha[" ${projects} /$branch " ]){
72
+ sha[" ${projects} /$branch " ] = jsonObject[" sha" ].toString()
71
73
return
72
74
}
73
- sha[projects.toString()] = sha1.toString()
75
+ // logger.warning("${sha["${projects}/$branch"]} => $sha1")
76
+
77
+ sha[" ${projects} /$branch " ] = jsonObject[" sha" ].toString()
78
+
74
79
75
80
val commit: Any? = jsonObject[" commit" ]
76
81
val committer: Any? = JSONObject .parseObject(commit.toString())[" committer" ]
@@ -88,10 +93,9 @@ class Commits {
88
93
val committers: Any? = jsonObject[" committer" ]
89
94
avatar = JSONObject .parseObject(committers.toString())[" avatar_url" ]
90
95
91
- if (num >= project.size) {
92
96
93
97
for (e in groups) {
94
- for ((index, bot) in bots.withIndex() ){
98
+ for (bot in bots){
95
99
bot.getGroup(e.toString().toLong())?.sendMessage(
96
100
process(
97
101
message = message.toString(),
@@ -109,7 +113,7 @@ class Commits {
109
113
}
110
114
111
115
for (u in users) {
112
- for ((index, bot) in bots.withIndex() ){
116
+ for (bot in bots){
113
117
bot.getStranger(u.toString().toLong())?.sendMessage(
114
118
process(
115
119
message = message.toString(),
@@ -122,9 +126,7 @@ class Commits {
122
126
}
123
127
124
128
}
125
- } else {
126
- num + = 1
127
- }
129
+
128
130
}
129
131
response.closeQuietly()
130
132
} catch (e: Exception ) {
0 commit comments