зеркало из https://github.com/Azure/spec-sla-bot.git
Коммит
ec3167b4f4
|
@ -10,7 +10,7 @@ WORKDIR $GOPATH/src/github.com/Azure/spec-sla-bot
|
|||
#ADD yarn.lock .
|
||||
#RUN yarn install --no-progress
|
||||
ADD . .
|
||||
RUN go get $(go list ./... | grep -v /vendor/)
|
||||
RUN dep ensure
|
||||
RUN buffalo build --static --ldflags "-X github.com/Azure/spec-sla-bot/actions.commitID=$(git rev-parse HEAD)" -o /bin/app
|
||||
|
||||
FROM alpine
|
||||
|
|
|
@ -60,10 +60,11 @@ func CheckAcknowledgementLabel(event github.LabelEvent) {
|
|||
func updateTime() time.Time {
|
||||
currentTime := time.Now().Local()
|
||||
//Adjusted time for now for testing purposes
|
||||
/*if strings.EqualFold(currentTime.Weekday().String(), "Friday") {
|
||||
currentExpireTime := currentTime.Add(time.Hour * time.Duration(48))
|
||||
//if the current weekday is Friday
|
||||
if currentTime.Weekday() == 5 {
|
||||
currentExpireTime := currentTime.Add(time.Hour * time.Duration(72))
|
||||
return currentExpireTime
|
||||
}*/
|
||||
}
|
||||
currentExpireTime := currentTime.Add(time.Minute * time.Duration(5))
|
||||
return currentExpireTime
|
||||
}
|
||||
|
@ -71,32 +72,25 @@ func updateTime() time.Time {
|
|||
func checkCommented(event github.IssueCommentEvent, tx *pop.Connection) bool {
|
||||
//check that the issue is not nil and that the issue id is a pr id in the db
|
||||
if event.Issue != nil && event.Issue.Assignee != nil && event.Sender != nil && event.Sender.Login != nil {
|
||||
expireTime := updateTime()
|
||||
validTime := true
|
||||
//Check if the right person assignee commented
|
||||
if strings.EqualFold(*event.Issue.Assignee.Login, *event.Sender.Login) {
|
||||
/*
|
||||
id, err := uuid.NewV1()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
q := tx.RawQuery(`INSERT INTO pullrequests (id, created_at, updated_at, git_prid, url, html_url, issue_url, number, state,
|
||||
valid_time, title, body, request_created_at, request_updated_at, request_merged_at,
|
||||
request_closed_at, commits_url, status_url, expire_time)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT (git_prid) DO UPDATE SET valid_time=?, expire_time=?`,
|
||||
id, time.Now(), time.Now(), *event.Issue.ID, *event.Issue.URL,
|
||||
*event.Issue.HTMLURL, *event.Issue.IssueURL, *event.PullRequest.Number,
|
||||
*event.PullRequest.State, valid_time, *event.PullRequest.Title, "",
|
||||
NullCheckTime(event.PullRequest.CreatedAt), NullCheckTime(event.PullRequest.UpdatedAt),
|
||||
NullCheckTime(event.PullRequest.MergedAt), NullCheckTime(event.PullRequest.ClosedAt),
|
||||
NullCheckInt(event.PullRequest.Commits), *event.PullRequest.StatusesURL, expire_time, valid_time, expire_time)
|
||||
err = q.Exec()
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
log.Print("Unable to update event number %d", *event.Number)
|
||||
return errors.New("Could not complete upsert")
|
||||
}
|
||||
return true
|
||||
*/
|
||||
prs := []models.Pullrequest{}
|
||||
err := tx.RawQuery(`SELECT * FROM pullrequests WHERE issue_url=?`, event.Issue.URL).All(&prs)
|
||||
if err != nil || prs == nil {
|
||||
log.Print("Could not make query")
|
||||
return false
|
||||
}
|
||||
//Might not be the best
|
||||
issueURL := prs[0].IssueUrl
|
||||
if strings.EqualFold(*event.Issue.Assignee.Login, *event.Sender.Login) && strings.EqualFold(*event.Issue.URL, issueURL) {
|
||||
q := tx.RawQuery(`UPDATE pullrequests SET valid_time=?, expire_time=? WHERE issue_url=?`, validTime, expireTime, issueURL)
|
||||
err := q.Exec()
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
log.Printf("Unable to update event number %d", *event.Issue.ID)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,7 @@ func SendEmailToAssignee(ctx context.Context, info *Message) error {
|
|||
fmt.Print(err)
|
||||
return err
|
||||
}
|
||||
str := string(b) // convert content to a 'string'
|
||||
//fmt.Print(str)
|
||||
str := string(b)
|
||||
m := gomail.NewMessage()
|
||||
//Get connection string from azure
|
||||
emailUrl := os.Getenv("CUSTOMCONNSTR_EMAIL_URL")
|
||||
|
@ -34,9 +33,7 @@ func SendEmailToAssignee(ctx context.Context, info *Message) error {
|
|||
}
|
||||
|
||||
port, _ := strconv.Atoi(parsed.Port())
|
||||
//user := parsed.User.Username()
|
||||
password, _ := parsed.User.Password()
|
||||
//email := user + "@" + parsed.Hostname()
|
||||
|
||||
queryString := fmt.Sprintf("SELECT EmailLogin FROM [User] WHERE GitHubUser = '%s';", info.Assignee)
|
||||
fmt.Println("email selection query: ", queryString)
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
"github.com/Azure/azure-service-bus-go"
|
||||
"github.com/Azure/spec-sla-bot/models"
|
||||
"github.com/gobuffalo/uuid"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
|
@ -46,6 +47,11 @@ func ReceiveFromQueue(ctx context.Context, connStr string) (*servicebus.Listener
|
|||
log.Println(err)
|
||||
return message.DeadLetter(err)
|
||||
}
|
||||
err = AddEmailToDB(messageStruct)
|
||||
if err != nil {
|
||||
log.Println("Unable to add the emails to the database")
|
||||
return message.DeadLetter(err)
|
||||
}
|
||||
}
|
||||
return message.Complete()
|
||||
})
|
||||
|
@ -108,3 +114,21 @@ func ShouldSend(messageStruct *Message) bool {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func AddEmailToDB(messageStruct *Message) error {
|
||||
gitPRID, _ := strconv.Atoi(messageStruct.PRID)
|
||||
id, err := uuid.NewV1()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
//Do I need to populate assignee?
|
||||
q := models.DB.RawQuery(`INSERT INTO emails (id, created_at, updated_at, pullrequest_id, time_sent)
|
||||
VALUES (?, ?, ?, ?, ?)`,
|
||||
id, time.Now(), time.Now(), gitPRID, time.Now())
|
||||
err = q.Exec()
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return errors.New("Could not complete insert to add email to database")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
create_table("emails", func(t) {
|
||||
t.Column("id", "uuid", {"primary": true})
|
||||
t.Column("pullrequest_id", "uuid", {})
|
||||
t.Column("time_sent", "string", {})
|
||||
t.Column("pullrequest_id", "int", {})
|
||||
t.Column("time_sent", "timestamp", {})
|
||||
})
|
|
@ -14,7 +14,7 @@ type Email struct {
|
|||
ID uuid.UUID `json:"id" db:"id"`
|
||||
CreatedAt time.Time `json:"created_at" db:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
|
||||
PullrequestID uuid.UUID `json:"pullrequest_id" db:"pullrequest_id"`
|
||||
PullrequestID int `json:"pullrequest_id" db:"pullrequest_id"`
|
||||
TimeSent string `json:"time_sent" db:"time_sent"`
|
||||
Assignees *Assignee `many_to_many:"email_assignee"`
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче