Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to invite to org: login object returns shortteam not team anymore #1

Open
chendaniely opened this issue Mar 6, 2023 · 0 comments

Comments

@chendaniely
Copy link

chendaniely commented Mar 6, 2023

I didn't run the add_team_to_github.py script directly, I was copy+pasting and running code line-by-line to slowly see what each step was doing. So this issue could just be a me problem.

The last for loop in the original script was returning an AttributeError where the .invite() method did not exist for that particular object.
Somehow I was getting a shortteam objectc, not a team object.

Original for loop:

# use invite function to invite team from csv file
for username in team_members.username.values:
    try:
        self.teams[team_name].invite(username)
    except:
        print(username, "failed to add to", team, "team")

My fix, using the .add_or_update_membership() method

for username in team_members.username.values:
    try:
        self.teams[team_name].add_or_update_membership(username)
        print(f"{username:<20} SUCCESS, {team:>10}, team")
    except:
        print(f"{username:<20} FAILED, {team:>10}, team")

My full script for reference:

import os

import github3
from github3 import login
import pandas as pd

org = "DSCI-310"
team = 'students-2022-23-w2'
team_name = team

canvas_data = pd.read_csv("/home/dan/SynologyDrive/work/ubc/2022-2023/w2/dsci-310/GitHub.com username survey Quiz Student Analysis Report - cleaned.csv")

team_members = canvas_data.loc[:, ["name", '5923110: Enter your GitHub.com username below.\n\nBe sure that:\n\nIt is the username (a combination of letters and numbers)\nNot an email address\nThe submitted text does not include line breaks, or more than one line.\n\nFor example, my GitHub username is:ttimbers']]
team_members.columns = ["name", "username"]

team_members["username"] = team_members["username"].str.strip().str.lower()
team_members.head()

token = "XXXXXXXXXX"

# log in
self = login(token=token)

orgname = org
self.org = self.organization(orgname)

self.teams = {team.name : team for team in self.org.teams()}
self.teams

# use 'students-2022-23-w2' in self.teams

team_members.username.values

# self.teams[team_name].add_or_update_membership("chendaniely-teaching")

# use invite function to invite team from csv file
# invite was for a team object, we currently have a shortteam object now
# so we use add_or_update_membership()
for username in team_members.username.values:
    try:
        self.teams[team_name].add_or_update_membership(username)
        print(f"{username:<20} SUCCESS, {team:>10}, team")
    except:
        print(f"{username:<20} FAILED, {team:>10}, team")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant