Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
garethahealy committed Jan 5, 2024
1 parent 4b1a7c5 commit 8d90b0f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,19 @@ jobs:
with:
name: target

- name: Make github-stats-*-runner executable
run: chmod +x github-stats-*-runner

- name: Run collect-stats for myself
env:
GITHUB_LOGIN: ${{ secrets.GITHUB_TOKEN }}
run: ./github-stats-*-runner collect-stats --organization=garethahealy

- name: Run collect-stats for myself
env:
GITHUB_LOGIN: ${{ secrets.GITHUB_TOKEN }}
run: echo "todo" #./github-stats-*-runner create-who-are-you-issues --dry-run=true --organization=garethahealy --issue-repo=github-stats --members-csv=tests/members.csv --fail-if-no-vpn=false

- name: Upload github-output.csv
uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # v4
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ public class CreateWhoAreYouIssueCommand implements Runnable {
@CommandLine.Option(names = {"-org", "--organization"}, description = "GitHub organization", required = true)
String organization;

@CommandLine.Option(names = {"-repo", "--org-repo"}, description = "Repo name for 'org'", required = true)
@CommandLine.Option(names = {"-repo", "--issue-repo"}, description = "Repo where the issues should be created, i.e.: 'org'", required = true)
String orgRepo;

@CommandLine.Option(names = {"-dry", "--dry-run"}, description = "Dry-run aka dont actually create the GitHub issues", required = true)
Boolean dryRun;
@CommandLine.Option(names = {"-dry", "--dry-run"}, description = "Dry-run aka don't actually create the GitHub issues", required = true)
boolean dryRun;

@CommandLine.Option(names = {"-i", "--members-csv"}, description = "CSV container current known members", required = true)
String membersCsv;

@CommandLine.Option(names = {"-vpn", "--fail-if-no-vpn"}, description = "Throw an exception if can't connect to LDAP", required = true)
boolean failNoVpn;

@Inject
CreateWhoAreYouIssueService createWhoAreYouIssueService;
Expand All @@ -29,7 +35,7 @@ public void run() {
try {
//TODO: for time being, always dry-run
dryRun = true;
createWhoAreYouIssueService.run(organization, orgRepo, dryRun);
createWhoAreYouIssueService.run(organization, orgRepo, dryRun, membersCsv, failNoVpn);
} catch (IOException | LdapException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public class CreateWhoAreYouIssueService extends BaseGitHubService {
@Inject
Logger logger;

public void run(String organization, String orgRepoName, boolean isDryRun) throws IOException, LdapException {
public void run(String organization, String issueRepo, boolean isDryRun, String membersCsv, boolean failNoVpn) throws IOException, LdapException {
GitHub gitHub = getGitHub();
GHOrganization org = gitHub.getOrganization(organization);

GHRepository orgRepo = org.getRepository(orgRepoName);
GHRepository orgRepo = org.getRepository(issueRepo);
List<GHUser> members = org.listMembers().toList();

Set<String> usernamesToIgnore = getUsernamesToIgnore();
Set<String> usernamesToIgnore = getUsernamesToIgnore(membersCsv);

logger.infof("There are %s members", members.size());
logger.infof("There are %s members we already have emails for who will be ignored", usernamesToIgnore.size());
Expand All @@ -55,7 +55,7 @@ public void run(String organization, String orgRepoName, boolean isDryRun) throw
"https://red.ht/github-redhat-cop-username");

if (isDryRun) {
logger.infof("DRY-RUN: Would have created issue for %s", current.getLogin());
logger.infof("DRY-RUN: Would have created issue for %s in %s", current.getLogin(), orgRepo.getName());
} else {
builder.create();

Expand All @@ -69,7 +69,7 @@ public void run(String organization, String orgRepoName, boolean isDryRun) throw
Set<String> membersLogins = getMembersLogins(members);
for (String current : usernamesToIgnore) {
if (!membersLogins.contains(current)) {
logger.infof("Have a google form response but they are not part the git hub org anymore for %s", current);
logger.infof("Have a google form response but they are not part the github org anymore for %s", current);
}
}

Expand All @@ -78,7 +78,7 @@ public void run(String organization, String orgRepoName, boolean isDryRun) throw
//ldapsearch -x -h ldap.corp.redhat.com -b dc=redhat,dc=com -s sub 'uid=gahealy'
Dn systemDn = new Dn("dc=redhat,dc=com");
try (LdapConnection connection = new LdapNetworkConnection("ldap.corp.redhat.com")) {
for (String current : getCollectedEmails()) {
for (String current : getCollectedEmails(membersCsv)) {
String uid = current.split("@")[0];
try (EntryCursor cursor = connection.search(systemDn, "(uid=" + uid + ")", SearchScope.SUBTREE)) {
boolean found = false;
Expand All @@ -93,16 +93,20 @@ public void run(String organization, String orgRepoName, boolean isDryRun) throw
}
}
} catch (InvalidConnectionException ex) {
logger.error("Unable to search ldap for users. Are you on the VPN?", ex);
if (failNoVpn) {
logger.error("Unable to search ldap for users. Are you on the VPN?", ex);
} else {
logger.warn("Unable to search ldap for users. Are you on the VPN?", ex);
}
}

logger.info("Ldap Lookup DONE");
}

private Set<String> getUsernamesToIgnore() throws IOException {
private Set<String> getUsernamesToIgnore(String membersCsv) throws IOException {
Set<String> answer = new HashSet<>();
CSVFormat csvFormat = CSVFormat.Builder.create(CSVFormat.DEFAULT).setSkipHeaderRecord(true).build();
try (Reader in = new FileReader("GitHub Red Hat CoP Members (Responses) - Form Responses 1.csv")) {
try (Reader in = new FileReader(membersCsv)) {
Iterable<CSVRecord> records = csvFormat.parse(in);
for (CSVRecord record : records) {
answer.add(record.get("What is your GitHub username?"));
Expand All @@ -112,10 +116,10 @@ private Set<String> getUsernamesToIgnore() throws IOException {
return answer;
}

private List<String> getCollectedEmails() throws IOException {
private List<String> getCollectedEmails(String membersCsv) throws IOException {
List<String> answer = new ArrayList<>();
CSVFormat csvFormat = CSVFormat.Builder.create(CSVFormat.DEFAULT).setSkipHeaderRecord(true).build();
try (Reader in = new FileReader("GitHub Red Hat CoP Members (Responses) - Form Responses 1.csv")) {
try (Reader in = new FileReader(membersCsv)) {
Iterable<CSVRecord> records = csvFormat.parse(in);
for (CSVRecord record : records) {
answer.add(record.get("Email Address"));
Expand Down
2 changes: 2 additions & 0 deletions tests/members.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Timestamp,Email Address,What is your GitHub username?
1/26/2022 15:37:03,[email protected],garethahealy

0 comments on commit 8d90b0f

Please sign in to comment.