
    Vh"                         d dl mZmZmZ eZdZdZdZd dl	Z	dZ
	 d dlZdZd dlmZmZ d d	lmZ d
 Zd Zd Zd Zedk(  r e        yy# e$ r  e	j                         Z
dZY Bw xY w)    )absolute_importdivisionprint_functiona  
module: github_webhook
short_description: Manage GitHub webhooks
description:
  - Create and delete GitHub webhooks.
requirements:
  - "PyGithub >= 1.3.5"
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
options:
  repository:
    description:
      - Full name of the repository to configure a hook for.
    type: str
    required: true
    aliases:
      - repo
  url:
    description:
      - URL to which payloads will be delivered.
    type: str
    required: true
  content_type:
    description:
      - The media type used to serialize the payloads.
    type: str
    required: false
    choices: [form, json]
    default: form
  secret:
    description:
      - The shared secret between GitHub and the payload URL.
    type: str
    required: false
  insecure_ssl:
    description:
      - Flag to indicate that GitHub should skip SSL verification when calling the hook.
    required: false
    type: bool
    default: false
  events:
    description:
      - A list of GitHub events the hook is triggered for. Events are listed at U(https://developer.github.com/v3/activity/events/types/).
        Required unless O(state=absent).
    required: false
    type: list
    elements: str
  active:
    description:
      - Whether or not the hook is active.
    required: false
    type: bool
    default: true
  state:
    description:
      - Whether the hook should be present or absent.
    type: str
    required: false
    choices: [absent, present]
    default: present
  user:
    description:
      - User to authenticate to GitHub as.
    type: str
    required: true
  password:
    description:
      - Password to authenticate to GitHub with.
    type: str
    required: false
  token:
    description:
      - Token to authenticate to GitHub with.
    type: str
    required: false
  github_url:
    description:
      - Base URL of the GitHub API.
    type: str
    required: false
    default: https://api.github.com

author:
  - "Chris St. Pierre (@stpierre)"
a  
- name: Create a new webhook that triggers on push (password auth)
  community.general.github_webhook:
    repository: ansible/ansible
    url: https://www.example.com/hooks/
    events:
      - push
    user: "{{ github_user }}"
    password: "{{ github_password }}"

- name: Create a new webhook in a github enterprise installation with multiple event triggers (token auth)
  community.general.github_webhook:
    repository: myorg/myrepo
    url: https://jenkins.example.com/ghprbhook/
    content_type: json
    secret: "{{ github_shared_secret }}"
    insecure_ssl: true
    events:
      - issue_comment
      - pull_request
    user: "{{ github_user }}"
    token: "{{ github_user_api_token }}"
    github_url: https://github.example.com

- name: Delete a webhook (password auth)
  community.general.github_webhook:
    repository: ansible/ansible
    url: https://www.example.com/hooks/
    state: absent
    user: "{{ github_user }}"
    password: "{{ github_password }}"
z
hook_id:
  description: The GitHub ID of the hook created/updated.
  returned: when state is 'present'
  type: int
  sample: 6206
NTF)AnsibleModulemissing_required_lib)	to_nativec                     | j                   d   | j                   d   | j                   d   rdndd}| j                   j                  d      }|r||d<   |S )Nurlcontent_typeinsecure_ssl10)r
   r   r   secret)paramsget)modulehook_configr   s      t/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/github_webhook.py_create_hook_configr      sZ    }}U#n5%}}^<#K ]]x(F &H    c           	      2   t        |      }	 | j                  d||j                  d   |j                  d         }dj                  i}d	|fS # t        j                  $ r5}|j                  d| j                  dt        |             Y d }~Ud }~ww xY w)
Nwebeventsactivenameconfigr   r   z%Unable to create hook for repository : msghook_idT)	r   create_hookr   githubGithubException	fail_json	full_namer   id)repor   r   hookerrdatas         r   r"   r"      s     (F-==*==*	   , twwD: !! -NNIcN, 	- 	--s   /A B!+BBc           	      r   t        |      }	 |j                          |j                  d||j                  d   |j                  d          |j                         }d|j                  i}|fS # t        j
                  $ r5}|j                  d| j                  dt        |             Y d }~Ud }~ww xY w)	Nr   r   r   r   z%Unable to modify hook for repository r   r   r!   )
r   updateeditr   r#   r$   r%   r&   r   r'   )r(   r)   r   r   changedr*   r+   s          r   update_hookr0      s     (F-		==*==*	 	 	, ++-
 twwDD= !! -NNIcN, 	- 	--s   AA. .B6+B11B6c                  T   t        t        t        dddg      t        dd      t        dddd	      t        ddd
      t        ddd      t        ddd      t        ddd      t        dddd      t        dd      t        ddd
      t        ddd
      t        ddd            ddd      } t        s | j                  t	        d      t
               	 t        j                  | j                  d   | j                  j                  d      xs | j                  j                  d      | j                  d         }	 j                  | j                  d!         }d }	 j%                         D ]/  }|j&                  j                  d'      | j                  d'   k(  s/ n d }d}i }|"| j                  d)   dk(  rt)        |       \  }}nL|&| j                  d)   d*k(  r	 |j+                          d}n$|"| j                  d)   dk(  rt/        ||       \  }} | j0                  d-d,|i| y # t        j                  $ r9}| j                  d| j                  d   dt        |              Y d }~6d }~ww xY w# t        j                  $ r9}| j                  d"| j                  d   dt        |              Y d }~fd }~wt        j                  $ rI}| j                  d#| j                  d!   d$| j                  d   dt        |              Y d }~d }~wt        $ r\}| j                  d%| j                  d!   d&| j                  d   dt        |      t!        j"                                Y d }~#d }~ww xY w# t        j                  $ r9}| j                  d(| j                  d!   dt        |              Y d }~+d }~ww xY w# t        j                  $ r6}| j                  d+j,                  dt        |              Y d }~d }~ww xY w).NstrTr(   )typerequiredaliases)r3   r4   )jsonformFr7   )r3   choicesr4   default)r3   r4   no_logbool)r3   r4   r9   list)r3   elementsr4   )absentpresentr?   )r3   r4   r8   r9   zhttps://api.github.com)
repositoryr
   r   r   r   r   r   stateuserpasswordtoken
github_url))rC   rD   ))rA   r?   )r   )argument_specmutually_exclusiverequired_one_ofrequired_ifPyGithub)r    	exceptionrB   rC   rD   rE   )base_urlzCould not connect to GitHub at r   r   r@   z$Could not authenticate to GitHub at zCould not find repository z in GitHub at zCould not fetch repository z from GitHub at r
   z$Unable to get hooks from repository rA   r>   z&Unable to delete hook from repository r/    )r   dict
HAS_GITHUBr%   r   GITHUB_IMP_ERRr#   Githubr   r   r$   r   get_repoBadCredentialsExceptionUnknownObjectException	Exception	traceback
format_exc	get_hooksr   r"   deleter&   r0   	exit_json)r   github_connr*   r(   r)   r/   r+   s          r   mainr\      s   xH%$/(	 
 UU4@6E5IVeeDVeTB-!	#
 540uuTBEE$?U4LN)O, 4083F8 1*=#1 	 	3:mmMM&!MMj)GV]]->->w-G]]<02.##FMM,$?@  D:NN$ 	D{{u%u)==	 D
 GD|g.);#D&1		fmmG4@	KKM G		fmmG4	A#D$7 F-W--c !! :MM,'39 	: 	:: )) :MM,'39 	: 	:(( !l+V]]<-H#  	 	! 	!  .]]<(&--*Es^  **,	 	 	. 	.. !! :MM,'39 	: 	:: %% 	5NNIcN4  5 5	5s   A(H4 J '>N &N (O 4J .I;;J N.K

N >L$$N0ANNO".OOP'1+P""P'__main__)
__future__r   r   r   r3   __metaclass__DOCUMENTATIONEXAMPLESRETURNrV   rP   r#   rO   ImportErrorrW   ansible.module_utils.basicr   r   +ansible.module_utils.common.text.convertersr   r   r"   r0   r\   __name__rM   r   r   <module>rg      s    C BYvB
 J
 K A &W.t zF g  )Y))+NJs   A A#"A#