Skip to content

Commit

Permalink
feat: GitHub connectors connect a project to watch - MEED-2195 - MEED…
Browse files Browse the repository at this point in the history
…-2299 - Meeds-io/MIPs#64 (#81)

Allow rewarding users to add GitHub organizations to watch.
  • Loading branch information
AzmiTouil committed Sep 12, 2023
1 parent cce84db commit 44e84a8
Show file tree
Hide file tree
Showing 45 changed files with 2,615 additions and 927 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
* Copyright (C) 2020 - 2023 Meeds Association [email protected]
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.exoplatform.gamification.github.dao;

import org.exoplatform.commons.persistence.impl.GenericDAOJPAImpl;
import org.exoplatform.gamification.github.entity.WebhookEntity;

import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;
import java.util.List;

public class WebHookDAO extends GenericDAOJPAImpl<WebhookEntity, Long> {

public static final String ORGANIZATION_ID = "organizationId";

public WebhookEntity getWebhookByOrganizationId(long organizationId) {
TypedQuery<WebhookEntity> query = getEntityManager().createNamedQuery("GitHubWebhooks.getWebhookByOrganizationId",
WebhookEntity.class);
query.setParameter(ORGANIZATION_ID, organizationId);
try {
return query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}

public List<Long> getWebhookIds(int offset, int limit) {
TypedQuery<Long> query = getEntityManager().createNamedQuery("GitHubWebhooks.getWebhookIds", Long.class);
if (offset > 0) {
query.setFirstResult(offset);
}
if (limit > 0) {
query.setMaxResults(limit);
}
return query.getResultList();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
* Copyright (C) 2020 - 2023 Meeds Association [email protected]
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.exoplatform.gamification.github.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.*;

import org.exoplatform.commons.api.persistence.ExoEntity;

import lombok.Data;
import org.exoplatform.gamification.github.utils.StringListConverter;

@Entity(name = "GitHubWebhooks")
@ExoEntity
@Table(name = "GITHUB_WEBHOOKS")
@NamedQuery(name = "GitHubWebhooks.getWebhookByOrganizationId",
query = "SELECT gitHubWebhook FROM GitHubWebhooks gitHubWebhook"
+ " WHERE gitHubWebhook.organizationId = :organizationId")
@NamedQuery(name = "GitHubWebhooks.getWebhookIds",
query = "SELECT gitHubWebhook.id FROM GitHubWebhooks gitHubWebhook"
+ " ORDER BY gitHubWebhook.id ASC")
@Data
public class WebhookEntity implements Serializable {

private static final long serialVersionUID = 2607146513663056421L;

@Id
@SequenceGenerator(name = "SEQ_GITHUB_WEBHOOKS_ID", sequenceName = "SEQ_GITHUB_WEBHOOKS_ID", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_GITHUB_WEBHOOKS_ID")
@Column(name = "ID")
private Long id;

@Column(name = "WEBHOOK_ID")
private Long webhookId;

@Column(name = "ORGANIZATION_ID", nullable = false)
private Long organizationId;

@Convert(converter = StringListConverter.class)
@Column(name = "TRIGGERS", nullable = false)
private List<String> triggers;

@Column(name = "ENABLED", nullable = false)
private Boolean enabled;

@Column(name = "WATCHED_DATE", nullable = false)
private Date watchedDate;

@Column(name = "WATCHED_BY", nullable = false)
private Long watchedBy;

@Column(name = "UPDATED_DATE", nullable = false)
private Date updatedDate;

@Column(name = "REFRESH_DATE", nullable = false)
private Date refreshDate;

@Column(name = "SECRET", nullable = false)
private String secret;

@Column(name = "TOKEN", nullable = false)
private String token;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
* Copyright (C) 2020 - 2022 Meeds Association [email protected]
* Copyright (C) 2020 - 2023 Meeds Association [email protected]
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
Expand All @@ -15,14 +15,15 @@
*/
package org.exoplatform.gamification.github.exception;

public class GithubHookException extends Exception {
public class GithubConnectionException extends Exception {

private static final long serialVersionUID = -2836988837493225118L;
private static final long serialVersionUID = -2437500058122638710L;

public GithubHookException() {
public GithubConnectionException(String message) {
super(message);
}

public GithubHookException(String message) {
super(message);
public GithubConnectionException(String message, Exception e) {
super(message, e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@

import java.util.Map;

import org.exoplatform.gamification.github.services.GithubHooksManagement;
import org.exoplatform.gamification.github.services.WebhookService;
import org.exoplatform.services.listener.Event;
import org.exoplatform.services.listener.Listener;

public class GithubEventsListener extends Listener<Map<String, String>, String> {

private GithubHooksManagement githubHooksManagement;
private final WebhookService webhookService;

public GithubEventsListener(GithubHooksManagement githubHooksManagement) {
this.githubHooksManagement = githubHooksManagement;
public GithubEventsListener(WebhookService webhookService) {
this.webhookService = webhookService;
}

@Override
public void onEvent(Event<Map<String, String>, String> event) throws Exception {
public void onEvent(Event<Map<String, String>, String> event) {
String ruleTitle = event.getSource().get("ruleTitle");
String senderId = event.getSource().get("senderId");
String receiverId = event.getSource().get("receiverId");
String object = event.getSource().get("object");
githubHooksManagement.createGamificationHistory(ruleTitle, senderId, receiverId, object);
webhookService.createGamificationHistory(ruleTitle, senderId, receiverId, object);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

public class GithubAccessTokenContext extends AccessTokenContext implements Serializable {

private static final long serialVersionUID = 659507333834536163L;

public final OAuth2AccessToken accessToken;

public GithubAccessTokenContext(OAuth2AccessToken accessToken) {
Expand All @@ -35,6 +37,7 @@ public String getAccessToken() {
return accessToken.getAccessToken();
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
* Copyright (C) 2020 - 2023 Meeds Association
* [email protected]
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package org.exoplatform.gamification.github.model;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class RemoteOrganization {

long id;

String name;

String title;

String description;

String avatarUrl;
}
Loading

0 comments on commit 44e84a8

Please sign in to comment.