1

I have an Github Bot (Probot) that I use to handle automation for things like naming conventions etc etc.

I also have a number of teams that we use for controlling visibility and I was wondering if it's possible to use the Probot to assign certain teams access when a Repo is created from a particular template.

However I have analysed the context object and searched through it looking for the template repo name but cant seem to find a solid way of determining where the repo was created from. Maybe I'm missing something here or is this not possible at all? See code attached

const templateTeamAssignment = async (context) => {
  const { github, payload } = context;
  const repo = payload.repository.name;

  console.log("context", context);
};

module.exports = templateTeamAssignment;

Any ideas?

cshocks
  • 11
  • 1

2 Answers2

0

The event payload does not include the template_repository property you are looking for. But you can retrieve the information by retrieving the repository's information using a REST API call or a GraphQL query. For example, try this

const { template_repository } = await context.github.repos.get(context.repo())

If template_repository is unset it means the repository was not created using a template repository.

Gregor
  • 2,325
  • 17
  • 27
  • Unfortunately @Gregor that didn't do it. It did shine some light on the `baptiste-preview` which I would need to provide as a header in order to show the `is_template` and `template_repository` properties like you mentioned. They are also only visible on the `listForOrg` function. When I implemented this, I was able to see the `is_template` property but not the `template_repository` which leads me to believe that it's not yet stable enough for production and this was confirmed by the warning on the API docs. For now I will have to go without unless you have other ideas? – cshocks Nov 02 '20 at 19:24
  • The previews are being graduated one-by-one, they should be quite stable. I'd suggest to reach out to GitHub's support at https://support.github.com/contact, they will be able to help the best – Gregor Nov 03 '20 at 20:10
  • Thanks for that @Gregor, I'll try that and report back here if I manage to solve it – cshocks Nov 05 '20 at 02:15
0

Unfortunately I don't think this is possible at present. I did manage to figure out that the baptiste-preview would need to be provided as a header in order to show the is_template and template_repository properties in the result. They are also only visible on the listForOrg() function so I would have to loop through the result find the individual repo information.

const templateTeamAssignment = async (context) => {
  const { github, payload } = context;
  const repo = payload.repository.name;

  console.log("context", context);

  console.log("stackOverflow", await context.github.repos.get(context.repo()));
  console.log(
    "stackOverflow",
    await context.github.repos.listForOrg({
      org: payload.organization.login,
      headers: {
        accept: "application/vnd.github.baptiste-preview+json",
      },
    })
  );
};

When I implemented this, I was able to see the is_template property but not the template_repository which leads me to believe that it's not yet stable enough for production and this was confirmed by the warning on the API docs. Would love to know if anyone is currently having success with getting the template_repository property?

cshocks
  • 11
  • 1